Hacker News new | ask | show | jobs
by dmitriid 1710 days 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.

2 comments

That contradicts my experience and what I just described. In my experience, sites do feel instant even if they load dozens of scripts.
If 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.

If 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.

There 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.
Browsers are good at caching JavaScript files, so it depends if the scripts are already cached or not.
I 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...

Khan 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/

You 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.