18

Oct

HTTP/2 vs HTTP/1.1
 

You should always use HTTP/2 for your websites - it dramatically improves website performance with no downside. Here's a simple example video that shows how significant this improvement can be.

The HTTP/2 protocol was standardized in 2015, and is designed to solve many issues that the HTTP/1.1 protocol has with modern websites. When HTTP 1.1 was introduced in 1997, web pages had some HTML markup, and few images. Now, web pages can contain hundreds of resources - images, fonts, scripts, stylesheets, etc.

Because HTTP/1.1 was not designed to handle such loads, web developers have come up with a bunch of different hacks to improve the load speed of pages.  These hacks attempt to reduce the number of HTTP requests to the server, because establishing an HTTP connection carries a lot of overhead and doing that for hundreds of resources slows down the rendering of the page, which causes user frustration and leads to high bounce rates. Some of the popular hacks include domain sharding, image sprites, and concatenation and minification of JavaScript and CSS files.

HTTP/2 improves website performance in multiple ways. It compresses the HTTP headers, allows for Server Push (which can send resources to the browser before the HTML document is completely downloaded and parsed) and enables Multiplexing, which allows the client and server to process multiple requests over the same connection.  That reduces all of the overhead of establishing many HTTP connections.

Let's see how this works in practice. In this video, I have set up Tomcat to listen on two different ports. Port 18020 has HTTP/2 enabled, while port 18011 uses HTTP/1.1 only. Both ports serve the same application with the same code base.  To demonstrate the difference, I took an image and sharded it into hundreds of pieces, so that the HTML page would need to request many resources.  I also disabled the caching of those resources.


In the demo above, the network latency from workstation to the server is clocked at about 65ms, which is very reasonable (a ping from the same workstation to google.com takes 71ms). The higher the latency, the more of an improvement that HTTP/2 will provide, so if your website has visitors from other countries or other continents, the improvement can be orders of magnitude better.

Network latency from workstation to Rasia.io


Even though the HTTP/2 protocol was introduced more than 3 years ago, it is estimated that only 30% of websites utilize it as of October of 2018.  HTTP/2 is an Upgrade protocol, so if the browser doesn't support the new protocol, it will still work fine with HTTP/1.1, but if the browser does support it, the connection will be upgraded to the HTTP/2 protocol.  Given that "fallback" support, there are many reasons to set up HTTP/2 on your server, and no reason not to.

This demo was inspired by presentations from Simone Bordet of the Eclipse Jetty team, and Jean-Frederic Clere of the Apache Tomcat team.


Social Media

FOLLOW US