4 ms·
> How many scripts does a site need to make it feel faster when bundled? Depends on what you're building. If you have many nested dependencies, you need to bun
by dmitriid 5y ago
> How many scripts does a site need to make it feel faster when bundled?
Depends on what you're building. If you have many nested dependencies, you need to bundle them, and not rely on the browser to resolve them at runtime and do dozens of roundtrips to the server to fetch them.
- TekMol 5y agoThat contradicts my experience and what I just described. In my experience, sites do feel instant even if they load dozens of scripts.
- dmitriid 5y agoThere will definitely be an inflection point, and it's very dependent on many factors: number and size of scripts, how much of the initial content is SSRed, network bandwidth and latency etc.
- _old_dude_ 5y agoBrowsers are good at caching JavaScript files, so it depends if the scripts are already cached or not.
- setr 5y agoIf your dozens of scripts are top-level (on the html itself) then you can fetch all of them in parallel — so you wait your connection speed roughly twice (roundtripped). If they’re nested dependencies (where you don’t identify the next necessary js until you have the first one in hand), the dependency won’t start getting fetched until the predecessor is retrieved. So you wait your connection speed multiplied by depth (x2; roundtripped) The goal of the bundler is to take the second scenario and turn it into the first scenario.
- eknkc 5y agoIf they are not waterfalling then yeah. But when a depends on b and b depends on c you will be fetching those serially. The bundler will have those preprocessed and bundled together.
- hivacruz 5y agoI thought HTTP 2 fixed the problem of multiple downloads of small files/dependencies? The creator of Rails talks about it here: https://world.hey.com/dhh/modern-web-apps-without-javascript-bundling-or-transpiling-a20f2755 https://world.hey.com/dhh/modern-web-apps-without-javascript...
- eyelidlessness 5y agoYou can use the Network tab of your preferred browser to see the waterfall. HTTP2 did improve a lot, but it can’t magically resolve N-deep transitive imports without additional information. It was originally designed to have that information provided at the server level, but HTTP Push has been dead for a while. There are physical limitations at work, optimizing requests on the wire is still important.
- beeandapenguin 5y agoKhan Academy did a great writeup on their experience (including thoughts about HTTP/2) with various strategies for serving JS, such as: - Single bundle - No bundles (all separate files) - Hybrid https://blog.khanacademy.org/forgo-js-packaging-not-so-fast/ https://blog.khanacademy.org/forgo-js-packaging-not-so-fast/