Closed yoshuawuyts closed 1 year 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.
@terinjokes in your opinion, what could be done to improve this? Any particular parts of integrating it that didn't feel right?
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.
localhost:3000
( local ) or https://some.s3.bucket
( deployed to staging and / or production ) <script src="https://some.s3.bucket/main.js">
and </script><script src="https://some.s3.bucket/a.js"></script>
during static render and not re-append the a.js
file on load.moment.js
that you only use on three of the 20 urls you should be able to externalize this file at bundle time and only append it as well as the page file as needed. package.json
( which is my ideal approach ) or another external configuration file, or in a build script.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 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.
As per https://github.com/browserify/discuss/issues/5:
Input on the topic would be greatly appreciated!
cc/ @kristoferjoseph @brianleroux