HTTP/2 and Concatenation

I’ve seen it repeated over and over how HTTP/2 means that you no longer have to concatenate resources. The context is usually around JavaScript, but it is similar for CSS. Real world tests don’t always line up with that theoretical expectation, as demonstrated by Khan Academy back in 2015. Here is their summary:

HTTP/2.0, with its multiplexing, header compression, and the like, offers the promise of the best of all worlds when it comes to downloading JavaScript: great local caching, great download efficiency, no wasted bytes, and a simpler serving infrastructure to boot. All you have to do is give up your packaging system and download all your JavaScript source files individually.

The reality is not so rosy. Due to degraded compression performance, the size of the data download with individual source files ends up being higher than with packages, despite having achieved ‘no wasted bytes’. Likewise, the promised download efficiency has yet to show up in the wild, at least for us. It seems that, for the moment at least, JavaScript packaging is here to stay.

From what I’ve seen so far, there is some line that balances between too much concatenation and too little. Unfortunately I think that line is going to vary from site to site. If we are lucky, we might get some good guidelines ( always concat if loading fewer than X bytes ) that can be applied by tools and services automatically.

Having hard rules that “always make things better 100% of the time” are becoming less common in the world of HTTP/2, modern browsers, and mobile clients. There is no substitute for making measurements and comparing the results.