browserify / discuss

discuss project organization, initiatives, and whatever!
11 stars 1 forks source link

Async module loading / bundle splitting #6

Closed yoshuawuyts closed 11 months ago

yoshuawuyts commented 7 years ago

As per https://github.com/browserify/discuss/issues/5:

Probably the largest unsolved problem in the ecosystem is asynchronous module loading / splitting files into multiple small files. factor-bundle allows extracting shared code between bundles. The bundles then rely on being loaded in the right order. partition-bundle is similar, but allows bundles to be loaded with a loadJS() function.

Input on the topic would be greatly appreciated!

cc/ @kristoferjoseph @brianleroux

terinjokes commented 7 years ago

From our experience here at Cloudflare, getting factor-bundle to work reasonably well was a real hassle. It definitely felt bolted on, rather than something that's part of the Browserify project.

yoshuawuyts commented 7 years ago

@terinjokes in your opinion, what could be done to improve this? Any particular parts of integrating it that didn't feel right?

kristoferjoseph commented 7 years ago

Description

Hello all, I've been researching code-splitting with browserify for a bit now and can share what success criteria looks like for me.

I can break down what would be ideal — with some explanation as to why — then list out my experiences with using existing libraries and what deficiencies i ran into using them.

This is a fairly complex issue so please bear with me, also please by no means take this as gospel. This is just meant to add some ideas about success criteria based on using this approach "in anger" while building a real app.

success criteria

partition-bundle discovery

partition-bundle on github Here is an example build file that uses partition-bundle

For me partition bundle works pretty well. It satisfies almost all of my success criteria save for splitting out page specific css files, but this could be a sheetify plugin concern.

The example build file shows passing the main file, entry files as well as a url for local and deployed loading of files with the bundled loadjs

factor-bundle discovery

factor-bundle on github factor-bundle is really very powerful for factoring out common code. With the correct combination of exclude and require settings in the browserify arguments you could achieve similar results as partition-bundle.

However you would need to come up with your own loader which might be a good idea in that it separates concerns, but it does make it a non-viable option out of the box.

Another issue i ran into was it didn't put files into a main entry file with multiple other entry points. In my experience it only separated out shared modules into a common bundle. For me it would be better to have one file that manages common code as well as loading other externalized modules.

Anyways, there are some thoughts, hopefully they help.