I've read that HTTP2 removes the need for JavaScript file concatenation because of the multiple -> single connection change.
But doesn't concatenating still reduce the amount of headers that are sent? If there are separate files sent won't each one be sent with its own set of headers?
With concatenation only one set of headers will be sent.
So would concatenation still make a small difference?
Under HTTP/1.1 yes this would help.
Under HTTP/2 headers are compressed using HPACK. This builds a table of headers which are then referenced in future requests with the same headers, so the full header is not sent again but just a much smaller reference to the previous header.
However, there are other points to consider.
Reasons to concatenate:
Body compression (e.g. Gzip) works better on larger resources so concatenating will likely mean less bytes are transferred.
There is still an overhead to Browsers making extra requests. Whether from creating the request, sending it, parsing it...etc. The network impact is reduced under HTTP/2 but there are still benefits to concatenation.
Reasons NOT to concatenate:
If you only send the resources you need then there may be savings. E.g. let's assume you have three javascript files (1.js
, 2.js
and 3.js
), and normally send a combined javascript file (e.g. all.js
). Now, under HTTP/2 the penalty for not concatenating is not as severe, so you could only send what you need. So if a page only needs 1.js
and 3.js
, and only send those, then you save bytes by not sending 2.js
(and the processing on the browser side!). Of course this could also have been done under HTTP/1.1 if you also created a 1_and_3.js
file but creating all the combinations of concatenations may not have been worth the effort whereas not concatenating actually saves a build step.
Similarly on the caching side, if you do not concatenate, and then change 1.js
, you may still be able to use 2.js
and 3.js
from the cache. Previously the user would have had to download the full all.js
file again for any code changes.
So there is no clear cut answer but in my experience we will concatenate less (basically into functional bundles), but not eradicate it completely.
HTTP/2 makes things very interesting, in my opinion, and potentially lead to lots of changes in Web Performance Optimisations (WPO).