What Is HTTP/2?

HTTP/2 is a major revision of the HTTP protocol. It was released in May 2015 and is designed to improve web performance by allowing browsers to send multiplexed requests to servers. The servers, in return, can send multiplexed responses to browsers, compress headers, and push content to the browser before it is requested. 

These new capabilities enable servers and browsers that communicate over HTTP/2 to consume fewer resources, experience lower latency, and achieve higher efficiency compared to those that communicate over the HTTP/1.1 protocol that preceded it. 

Despite this improvement, HTTP/2 is not a substitute for HTTP/1.1. The Internet Engineering Task Force (IETF), the body responsible for creating and managing the HTTP standard, considers HTTP/2 an alternative, and not a replacement for HTTP/1.1. 

What Is HTTP?

To properly understand HTTP/2, we have to understand HTTP. HTTP (short for Hypertext Transfer Protocol) is the standard protocol for transferring data on the web. You can think of it as the language that browsers and servers use to communicate with one another. 

For example, when a user wants to access a website, they enter the URL into their browser. Their browser then sends an HTTP request to the server, requesting the files containing the text, images, and scripts on the webpage.

For example, the browser may send the request below:

GET / HTTP/1.1 
Host: yourdomain.com 
User-Agent: Chrome/Windows 
Accept: text/html 
Accept-Language: en-US

The server then processes the request and returns its response in HTTP format.

HTTP/1.1 200 OK 
Content-Type: text/html; charset=UTF-8 
Content-Length: 1256 
Date: Mon, 01 Jan 2025 12:00:00 GMT 
Server: Apache 
Connection: close

The above request and response were sent in HTTP/1.1 format. However, HTTP/1.1 and HTTP/2 are just two of the multiple HTTP protocols available. The entire HTTP protocol includes:

  • HTTP/0.9 (released in 1991)
  • HTTP/1.0 (released in 1996)
  • HTTP/1.1 (released in 1997 and is the first major HTTP version)
  • HTTP/2 (released in 2015 and is the second major HTTP version)
  • HTTP/3 (released in 2022 is the third major HTTP version)

How HTTP/2 Improves on HTTP/1.1

HTTP/2 has three major improvements over HTTP/1.1. They are:

  • Multiplexing
  • Header compression
  • Server push

1 Multiplexing

Multiplexing is the major improvement HTTP/2 has over HTTP/1.1. It refers to HTTP/2’s ability to send and receive multiple requests and responses simultaneously over a single connection. 

HTTP/1.1 lacked this capability and typically handled requests in a sequential manner. This means the server must return a response for a previous request before the browser can proceed with the next request on the same connection. 

This sometimes leads to the head-of-line blocking (HOL blocking) problem, which occurs when a slow request or response delays subsequent requests. This causes slow page load speeds, which hurts the user experience for visitors. 

You can think of HTTP/1.1 as a queue where the person in front needs to be served before the next person can be served. If the person in front is stuck at the server for whatever reason, then the queue gets delayed, and those at the back do not get served. 

Developers using HTTP/1.1 can limit this problem by opening multiple connections. However, this consumes additional resources and can still lead to head-of-line blocking if one of the requests or resources is slow. 

HTTP/2 solves the head-of-line problem (at the HTTP level) using multiplexing. This means the browser sends multiple requests at once, while the server returns responses as soon as they are ready, without having to wait for other requests and responses to be completed. 

2 Header Compression

HTTP requests and responses typically include a header containing important metadata about the request or response. In HTTP/1.1, the headers of these requests and responses are sent as plain, uncompressed, human-readable text.

While great for readability, they are not optimized for speed and can slow down your page load speed, especially when you are on a slow network or when the browser and server exchange multiple requests and responses

HTTP/2 improves on this by compressing the header using the HPACK header compression format. HPACK replaces commonly used header keys and values with short numeric codes, while also providing an encoding system for unique header keys and values.

For example, this HTTP/1.1 header below specifies:

  • The browser (User-Agent: Mozilla/5.0)
  • The URL the browser wants to access (Host: yourdomain.com)
  • The URL path the browser wants to access (/index.html)
  • The language in which the browser expects the response (Accept-Language: en-US)
GET /index.html HTTP/1.1
Host: yourdomain.com
User-Agent: Mozilla/5.0
Accept: text/html
Accept-Language: en-US
Connection: keep-alive

Meanwhile, this is what the HTTP/1.1 request above will look like if it were created using the HTTP/2 protocol. As you can see, the HTTP/2 protocol is unreadable to humans. However, browsers and servers understand it.

00 00 5f 01 05 00 00 00 01
82
87
84
8f
40 0a 75 73 65 72 2d 61 67 65 6e 74 0d 4d 6f 7a 69 6c 6c 61 2f 35 2e 30
40 06 61 63 63 65 70 74 09 74 65 78 74 2f 68 74 6d 6c
40 10 61 63 63 65 70 74 2d 6c 61 6e 67 75 61 67 65 05 65 6e 2d 55 53

3 Server Push

HTTP/2 allows the server to send resources to the browser before they are requested. For instance, when a browser requests a resource’s HTML file, the server sends the HTML file along with the CSS and JavaScript files. 

This feature is called server push, and is very helpful because it saves the browser from sending multiple requests to access resources on the server. It also enables visitors to access content and resources quickly, ultimately enhancing the user experience. 

However, server push can waste bandwidth, particularly when the user does not need the pushed resource or already has it cached on their device. Overall, the feature is largely unpopular and is rarely used, except in specific instances. 

HTTP/2 Best Practices

HTTP/2 remains the most widely used HTTP protocol today. Many developers prefer it over the older HTTP/1.1 and even the newer HTTP/3. That said, it is a great idea to keep these best practices in mind when using it. 

1 Only Use HTTP/2 over HTTPS Connections

Modern browsers only support HTTP/2 when used over a secure HTTPS connection. If the connection is not secure, the system will fall back to HTTP/1.1. 

You can avoid this by including a Transport Layer Security (TLS) certificate, also known as a Secure Sockets Layer (SSL) certificate, on webpages and servers you configure to run over HTTP/2. 

2 Use Server Push Sparingly

HTTP/2’s server push feature can improve performance by sending resources to the browser before it requests them. However, while it speeds up page load time, it can waste bandwidth, strain server resources, and delay the loading of other critical resources. 

To avoid performance issues, ensure to use the server push feature sparingly. Many developers only use it to push high-priority resources like CSS and above the fold images. For other resources, they use the HTML preload value (rel="preload").

3 Avoid Unnecessary Redirects

Redirects create round-trip delays, which can cancel out the benefits of HTTP/2. You can reduce the chances of this happening by specifying your desired URLs using a canonical tag. This makes it more likely that search engines will recognize your canonical URLs and use them.

4 Avoid Domain Sharding

Domain sharding is the practice of splitting resources across multiple subdomains. This was useful in HTTP/1.1, where it allowed developers to bypass connection limits. However, it becomes counterproductive with HTTP/2. 

HTTP/2 supports multiplexing, which enables multiple streams to share a single connection. As a result, domain sharding is unnecessary and can actually degrade performance by forcing the browser and server to establish multiple TLS connections. This increases latency and consumes additional resources.

🇺🇸 English