Hacker News new | ask | show | jobs
by jsmith99 772 days ago
Many bundlers output module format - it makes features like code splitting (chunking into separate files) convenient.
1 comments

ES modules mean you don't need to bundle your code; you just include your index.js in HTML, and all 30,000 JS files of your project come to the user's browser without trouble or delay (let's wish them luck, lol). Since you're bundling, it doesn't matter which module type you use; CJS has worked with code splitting perfectly for over 10 years. However, it's a pain every time you try to import a CJS library in your ESM or vice versa. The truth is, you can't just drop all legacy CJS packages in most real-world projects.
> “all 30,000 JS files of your project come to the user's browser without trouble or delay (let's wish them luck, lol)”

If only there was something in the HTTP protocol to make it more efficient to load multiple requests from the same server. Alas that must be a pipe dream, and every little image and script is loaded separately.

Oh wait, it’s not 1996 anymore…?

Oh, tell me how your browser will load all files simultaneously when your dependency tree looks like A->B->C->D->E->...
I hear there's this new HTTP 2 spec that might be able to do something like that... but obviously we need to wait on browser support

/s