Forgo JavaScript packaging? Not so fast
engineering.khanacademy.org
engineering.khanacademy.org
> We are wondering that too. The page in question is the Khan Academy homepage for logged in users, and it's acquired a lot of, um, functionality over the years.
> The end result of our analysis is that our page isn't going to load any faster until we reduce the amount of JavaScript we use on the page. Tricks like trying to load a bunch of stuff in parallel, or aggressive caching, might seem like appealing shortcuts, but nothing replaces just auditing the code and making it need less "stuff."
At the end of the day, de-bloating is the best way to make your pages faster.
When trying to make themselves look good on online developer forums: 1/100th real development time
When estimating time involved for co-worker: 1/10th real development time
When estimating time involved for themselves at work: 1/2 real development time
If they prebuild a manifest they can add X-Associated-Content to the response headers and App Engine will take care of the rest. They of course need to make sure that their static file handling has very little overhead, since doing push this way does get each resource via a request.
Because http/2 can fetch more resources in parallel, and avoid blocking one fetch behind another. http/1.1 can only open a few connections to the server at once, and due to widespread bugs, each of those connections can't pipeline by sending multiple requests and waiting for multiple responses. So you can't eliminate all the round-trip latencies. With http/2, you can send all the requests and then wait for all the responses. So even without server push or server hinting, you could request the HTML, get it back, then request all the CSS and JS files in parallel, and get them all back.
When writing articles like this, there should really be more detail. We're all the scripts just script tags in the html? AMD dependencies discovered as the tree gets downloaded?
Unless you have an inefficient bundling scheme, bundling performs near optimally. It's biggest downside isn't perf but the annoyance related to having to build the bundles, scale issues on really large apps, debugging inconvenience, much worse caching characteristics, etc. HTTP2 can beat bundling perf but you're going to have to make use of http server push to do it.
App Engine has supported the X-Associated-Content header for a little while now, and also supports the Link header, with rel=preload, like:
Link: <https://example.com/other/styles.css>; rel=preload; as=style
See http://w3c.github.io/preload/The experiments described in this post were conducted early this year, and it looks like those developments are fairly new?
I just discovered this too: https://github.com/GoogleChrome/http2push-gae
Is this new-ish capability documented somewhere?
They're called bundles. Not 'packages', which already has a very distinct meaning (eg, https://www.npmjs.com/ or similar systems) in the JavaScript community.
So the most likely cause for the random slowdowns are when javascript files are loaded from disk to ram or some similar process.
For most cases, you'd have your javascript files sitting in-ram on a dedicated static file server cache such as apache or nginx and would not experience this kind of random slowdown. So more than likely this article does not apply to anybody not using google app engine.
while for the packaged-files test it arrives at 0.092s
Since it's the first request, there're no concurrent requests in the view.
Maybe they run their test while benchmarking it? Still, if the environment is different, I'm not sure if their timing numbers are truly significant
1. Load the cached resource
2. Fire off a background request for any delta updates
3. Apply delta and update cache
4. Next load use the new resource