HTTP/2 is a long-needed upgrade to the HTTP/1.1 protocol and came with some features that greatly improves how web sites are served to visitors. This page discusses some of the differences and how to enable configured Midnight to take advantage of the upgrade.
In HTTP/1.1, browsers are limited to one connection to the server for each file downloaded and only a few connections to each server at a time. This led to a few different patterns while developing sites:
- The use of CDNs to be able to serve more files at a time. So while the page
and a few images download from the site at
example.com, some CSS might be downloading from
The first is a problem because it prevents your site's files from all being in one place. This means more work updating the files, making sure you're uploading to the right server, and so on…
The second is a problem for two reasons: the first is that it forces pages that don't need certain styles or scripts to download them anyways, because they are bundled with the stuff they do need. This wastes bandwidth downloading code that isn't being used. The second reason is that a change to one piece of the bundle causes the entire file to be invalid. It has to be removed from the browser cache and redownloaded in full to receive the change.
With HTTP/2, browsers are able to download multiple files simultaneously over a single connection to the server. This means no more need for CDNs and no need to bundle assets together, because the separate files are downloaded together anyways! This also means that download sizes can be optimized for the page being viewed, because only the code necessary to render the page is being downloaded. Web developers can also rely on the browser cache more, since changing one file no longer invalidates a bunch of other things that didn't change.
The downsides of HTTP/1.1 outlined above are fixed in HTTP/2. However, the patterns formed around them - bundling of files especially - were formed because they helped the situation. It's better to have to take the time to download one large file once than to wait for the browser to download a bunch of small files, one at a time.
So, a site optimized for HTTP/2 by separating its stylesheets and scripts into smaller, separate files is then less optimized for HTTP/1.1. That is why Midnight offers the choice between the two.
Enabling HTTP/2 Support
Enabling support for HTTP/2 is easy: just one line in your site's configuration
true, and the site will build with loose assets.
Remove the line or set it to
false, and assets will be bundled together for