What is HTTP/2?

Share this article

What is HTTP/2?
HTTP/2 is the latest evolution of the Hypertext Transfer Protocol (HTTP). HTTP is the network protocol used to request and receive pages and data on the World Wide Web. The new technology will eventually supersede HTTP/1.1 which was standardized more than two decades ago.

This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.

HTTP/2 network protocol

How Does HTTP/2 Differ from HTTP/1.1?

Perhaps HTTP/2 is better understood as its original name: HTTP/2.0. It has its roots in the SPDY (pronounced speedy) protocol devised by Google in 2009. HTTP/1.1 has several issues. It was created at a time when web pages rarely exceeded 100Kb, CSS was not available and, while JavaScript had been introduced, it was rarely used for anything more than basic form validation or simple effects. High bandwidth, Ajax-powered, Single-Page Applications and client-side frameworks were many years away. No one could envisage pages making more than a few requests. HTTP/2’s main objectives were to reduce latency. It gets a little technical but efficiencies were achieved using several techniques…

1. HTTP/2 is Binary Data

HTTP/1.1 uses textual data which is generally less efficient across a network.

2. HTTP/2 Headers are Compressed

Information sent with a request describes the data, its origin, type, length, how long it can be cached, etc. Unlike HTTP/1.1, this is now compressed in HTTP/2.

3. HTTP/2 Uses Pipelining

In HTTP/1.1, the server must send responses in the same order the requests were received. HTTP/2 is asynchronous so smaller or faster responses can be handled sooner.

4. HTTP/2 is Multiplexed

In HTTP/1.1, only one request can be handled on a TCP connection at any time. Browsers typically open between four and eight connections but large or slow assets can cause the download of other files to be delayed. HTTP/2 permits multiple request and response messages on the same (single) connection at the same time.

5. HTTP/2 Implements Server Push

The server can send assets before they are requested. For example, you may reference a script at the bottom of your web page. In HTTP/1.1, the browser will download the HTML, parse it, then load the JavaScript file when its <script> tag is encountered. An HTTP/2 server can push the JavaScript file to the browser before it knows it’s required.

Is HTTP/2 Noticeably Better?

Results will differ from system to system but the HTTP/1.1 vs HTTP/2 with HTTPS test tool typically reports HTTP/2 being 10x faster despite occurring over a secure connection.

Can HTTP/2 Be Used Today?

Yes. However, HTTP/2 is only enabled when both the web server and the browser support the protocol. The connection will normally fall back to HTTP/1.1 when either end fails. At the end of 2016, almost 11% of the top ten million websites supported HTTP/2. All recent versions of Firefox, Safari, Edge, Chrome and the other Blink-based browsers support the protocol. You can test whether your host has enabled HTTP/2 by entering your website’s URL into the HTTP/2 Test tool provided by keycdn.com. If you’re using managed or shared hosting, your host might need to enable HTTP/2. Some may make it an option that you can switch on or off, so contact them directly if you are unsure. Ideally, it’s best to use a web host that enables HTTP/2 by default, like our hosting partner SiteGround
. They support HTTP/2 on all servers with no need for further action. Additionally, they have free Let’s Encrypt SSL certificates — these are a must when using HTTP/2 because most browsers support HTTP/2 only if it’s encrypted. If you’re running your own dedicated or virtual server, HTTP/2 will need to be enabled for whichever web server you are using. Most support the protocol directly or have installable modules. That includes Apache, nginx, LiteSpeed, Microsoft IIS and Node.js/Express but note that features can differ. For example, nginx does not support HTTP/2 Server Push at the time of writing. Consult your documentation for further information.

Do I Need to Update My Website?

No — HTTP/2 is backward-compatible with HTTP/1.1. However, some of the good development practises you use today may become anti-patterns in a more efficient HTTP/2 world. You are possibly using a build system or manual processes to:
  • convert many images into a single-image sprite
  • inline images in the HTML page or CSS files
  • concatenating and minifying CSS and JavaScript into single files.
Reducing the number of requests is good for HTTP/1.1 connections but numerous HTTP/2 requests are considerably less expensive. It is possibly better to deliver multiple files because, if one changes, you need only send the update. You may also be moving assets to different domains or CDNs to permit more open HTTP/1.1 connections. This is not necessary for HTTP/2 because you can make as many requests as you need on a single connection. It’s possible that separate domains could harm performance owing to the additional DNS look-ups and TCP connections which need to be opened. That said, I recommend a pragmatic approach. Concatenation will rarely be a problem unless you’re merging large source files which are prone to regular changes. Retain your build processes unless you can prove a large proportion of your users can use HTTP/2 and multiple files or single domains offer a significant performance boost.

Frequently Asked Questions about HTTP/2

What are the main differences between HTTP/1.1 and HTTP/2?

HTTP/2 is an upgrade from HTTP/1.1, designed to improve the speed and efficiency of data transfer between a client and a server. The main differences include binary framing, multiplexing, server push, and header compression. Binary framing allows for more efficient parsing of messages. Multiplexing enables multiple requests and responses to be sent simultaneously, reducing latency. Server push allows servers to send resources to the client before they are requested, improving load times. Header compression reduces overhead by compressing HTTP headers.

How does HTTP/2 improve website performance?

HTTP/2 improves website performance in several ways. It allows for multiplexing, which means multiple requests can be sent at the same time over a single TCP connection. This reduces the amount of time it takes for data to travel between the client and the server. HTTP/2 also uses header compression to reduce the size of HTTP headers, reducing the amount of data that needs to be transferred.

Is HTTP/2 compatible with all browsers and servers?

Most modern browsers and servers support HTTP/2. However, it’s important to note that not all features of HTTP/2 are supported by all browsers and servers. For example, some browsers do not support server push. It’s also worth noting that while HTTP/2 is designed to be backwards compatible with HTTP/1.1, some older browsers and servers may not support it.

How does HTTP/2 handle security?

HTTP/2 itself does not provide any additional security features beyond what is available in HTTP/1.1. However, it is often used in conjunction with HTTPS, which provides secure, encrypted communication between the client and the server. This combination of HTTP/2 and HTTPS can provide a significant improvement in both performance and security.

What is server push in HTTP/2 and how does it work?

Server push is a feature of HTTP/2 that allows a server to send resources to a client before they are requested. This can significantly improve page load times by reducing the number of round-trip times (RTTs) required to fetch all the resources needed to display a web page. When a client requests a resource, the server can send not only the requested resource, but also any other resources it anticipates the client will need.

How does HTTP/2 handle mobile devices?

HTTP/2 is designed to work well with mobile devices. Its features like multiplexing, header compression, and server push can significantly improve the performance of mobile websites by reducing latency and the amount of data that needs to be transferred.

What is the impact of HTTP/2 on SEO?

HTTP/2 can have a positive impact on SEO. Faster page load times can lead to better user experience, which is a factor in search engine rankings. Additionally, Google has indicated that it uses HTTP/2 for crawling websites, which could potentially lead to more efficient and frequent crawling.

How can I implement HTTP/2 on my website?

Implementing HTTP/2 on your website typically involves updating your web server software to a version that supports HTTP/2. You may also need to configure your server to enable HTTP/2 features like multiplexing and server push.

Can HTTP/2 and HTTP/1.1 coexist?

Yes, HTTP/2 is designed to be backwards compatible with HTTP/1.1. This means that clients and servers that support HTTP/2 can still communicate with clients and servers that only support HTTP/1.1.

What is the future of HTTP/2?

The future of HTTP/2 looks promising. It is already widely supported and used, and its features like multiplexing and server push are likely to become even more important as web applications continue to grow in complexity. Additionally, work is already underway on HTTP/3, which will introduce even more improvements to the protocol.

Craig BucklerCraig Buckler
View Author

Craig is a freelance UK web consultant who built his first page for IE2.0 in 1995. Since that time he's been advocating standards, accessibility, and best-practice HTML5 techniques. He's created enterprise specifications, websites and online applications for companies and organisations including the UK Parliament, the European Parliament, the Department of Energy & Climate Change, Microsoft, and more. He's written more than 1,000 articles for SitePoint and you can find him @craigbuckler.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week