Sub topic 11
HTTP/1.1, HTTP/2 and HTTP/3 compared
This chapter assumes you have read the earlier chapters on TCP, TLS and the HTTP request and response. You should know what a method, a status code and a header are. You should also know that TLS sits between TCP and HTTP. The chapter explains how the three HTTP versions carry the same messages in different ways, and how your browser picks one.
Same meaning, different wire format
HTTP has one set of semantics: methods such as GET and POST, status codes such as 200 and 404, headers, and a body. Every version keeps those. What changes between versions is how the messages are encoded and which transport carries them.
| Property | HTTP/1.1 | HTTP/2 | HTTP/3 |
|---|---|---|---|
| Encoding | Plain text | Binary frames | Binary frames |
| Transport | TCP | TCP | QUIC over UDP |
| Encryption | Optional (TLS) | Required by browsers | Always (TLS 1.3 inside QUIC) |
| Requests per connection | One at a time | Many in parallel (multiplexed) | Many in parallel (multiplexed) |
| Header compression | None | HPACK | QPACK |
| Head-of-line blocking | At the HTTP level | At the TCP level | Only within one stream |
| Typical port | 80 or 443 | 443 | 443 (UDP) |
Head-of-line blocking means that one slow or lost item holds up everything queued behind it. Each version moves this problem to a different layer.
HTTP/1.1: text and one request at a time
HTTP/1.1 is the version shown in the earlier request and response chapter. It is human-readable text:
GET /docs/intro?lang=en HTTP/1.1
Host: example.com
Accept: text/html
Connection: keep-alivePersistent connections (keep-alive) let a browser reuse one TCP connection for several requests. This avoids repeating the TCP and TLS handshakes. But on a single connection, the response to request 2 cannot start until the response to request 1 has finished. A large image can therefore delay a small stylesheet queued behind it. The standard allows pipelining (sending several requests without waiting), but responses must still come back in order. Servers and proxies handled it badly, so browsers turned it off.
Browsers work around this by opening several connections to the same host. Chrome and Firefox allow about six. Each extra connection costs a TCP handshake, a TLS handshake and its own congestion window. Sites also spread assets over several host names (domain sharding) to get more connections. Developers bundled files and merged images into sprites to cut the number of requests.
Headers are sent in full every time. Cookies can add hundreds of bytes to every request, including requests for tiny images.
HTTP/2: multiplexing on one connection
HTTP/2 keeps the semantics and changes the framing. Each message is split into binary frames. Each frame is tagged with a stream ID, and many streams share one TCP connection. The browser can request the CSS, the script and ten images at once. The server interleaves the response frames, and the browser reassembles them by stream ID.
Other changes:
- Pseudo-headers. The request line and the
Hostheader become:method,:scheme,:authorityand:path. Header names are lowercase. TheConnectionheader is not allowed. - HPACK compression. Both sides keep a table of headers they have already sent. A repeated
user-agentorcookiebecomes a short index instead of full text. - Stream prioritization. The browser can hint which responses matter most, such as CSS before images. Servers treat these hints unevenly.
- Server push. The server could send resources before they were requested. In practice it often sent files the browser already had cached, and Chrome removed support. Do not design around it.
HTTP/2 does not remove head-of-line blocking. It only moves it down to TCP. TCP delivers bytes in order, so one lost packet stalls every stream on the connection until the packet is retransmitted. On a lossy mobile network, one connection carrying 30 streams can be slower than six HTTP/1.1 connections.
Browsers only speak HTTP/2 over TLS. The version is chosen during the TLS handshake with ALPN (Application-Layer Protocol Negotiation). The client lists h2 and http/1.1 in its ClientHello message. The server picks one in its reply. No extra round trip is needed.
HTTP/3: HTTP over QUIC
HTTP/3 replaces TCP. It runs over QUIC, a transport built on UDP. UDP only sends datagrams, with no ordering or retransmission. QUIC rebuilds those features in user space, and it can change them without waiting for operating systems to update.
Key differences from HTTP/2:
- Independent streams. QUIC knows about streams. If a packet carrying stream 5 is lost, only stream 5 waits. Streams 1 to 4 keep delivering. This removes TCP-level head-of-line blocking.
- Merged handshakes. QUIC includes TLS 1.3. A new connection needs one round trip for transport and encryption together, instead of one for TCP plus one or two for TLS. Resuming a known server can send data in the first flight (0-RTT). 0-RTT data can be replayed by an attacker, so servers should accept only safe, idempotent requests in it.
- Connection IDs. A TCP connection is identified by the source and destination IP address and port. When a phone moves from Wi-Fi to cellular, its address changes and the connection breaks. A QUIC connection is identified by a connection ID, so it survives the move (connection migration).
- QPACK. This is HPACK redesigned so that header compression does not reintroduce blocking when packets arrive out of order.
How the browser chooses a version
A browser cannot know a server supports HTTP/3 before it connects. It discovers this in one of two ways. The first is an Alt-Svc response header received over HTTP/1.1 or HTTP/2. The second is an HTTPS record in DNS. The following diagram shows the decision.
The first visit to a site usually uses HTTP/2. The server's Alt-Svc: h3=":443"; ma=86400 header tells the browser that HTTP/3 is available on UDP port 443 for the next 86,400 seconds. Later connections can try QUIC. Browsers often race QUIC against TCP, or fall back to TCP if QUIC fails, because some networks block or throttle UDP.
Observing the version
curl can force a version and report what was used. The --http3 option works only if your curl build includes HTTP/3 support.
curl -sI --http1.1 -o /dev/null -w 'http1.1 request used: %{http_version}\n' https://example.com/
curl -sI --http2 -o /dev/null -w 'http2 request used: %{http_version}\n' https://example.com/
curl -sI --http3 -o /dev/null -w 'http3 request used: %{http_version}\n' https://example.com/
curl -sI https://example.com/ | grep -i '^alt-svc'In the browser console, the Navigation Timing entry records the protocol for the page itself. Resource entries do the same for subresources. A cross-origin resource reports an empty string unless the server sends Timing-Allow-Origin.
const [nav] = performance.getEntriesByType('navigation');
console.log('Page protocol:', nav.nextHopProtocol); // 'h2', 'h3' or 'http/1.1'
const counts = {};
for (const r of performance.getEntriesByType('resource')) {
const p = r.nextHopProtocol || 'unknown';
counts[p] = (counts[p] || 0) + 1;
}
console.log(counts);In DevTools, open the Network panel, right-click the column header and enable Protocol. You will see h2, h3 or http/1.1 beside each request.
Gotchas and common errors
- Old tuning advice backfires. Domain sharding under HTTP/2 splits traffic over several connections. Each connection pays its own handshake and loses the shared header table. Heavy bundling also stops caches from reusing unchanged files. Moderate bundling is still fine.
- The protocol applies per connection. One page can mix versions. For example, the main site may use h3 while a third-party script server uses http/1.1.
- Version does not change the cache rules.
Cache-Control,ETagand status codes work the same in all three. A cache hit avoids the network and so avoids the protocol entirely. - HTTP/3 is not always faster. On a fast, low-loss wired link, the three versions often perform about the same. HTTP/3 helps most on lossy or changing networks, and its UDP processing can cost more CPU on servers.
- Middleboxes may block UDP 443. Corporate firewalls often do. Browsers fall back to TCP, so the site still works, but you will see h2 in the Network panel.
- Proxies may downgrade. A reverse proxy can speak HTTP/2 to the browser and HTTP/1.1 to the application server. Measure at the browser, not only on the server.
Exercise
A page loads 40 small files from one host. A user on a lossy mobile network finds it slower over HTTP/2 than expected, even though HTTP/2 multiplexes requests. Explain why, and say which version addresses it and how.
Show answer
HTTP/2 multiplexes all 40 streams over one TCP connection. TCP delivers bytes strictly in order, so one lost packet stalls every stream until it is retransmitted. This is head-of-line blocking at the TCP level. HTTP/3 runs over QUIC, which tracks streams itself. A lost packet delays only the stream it belongs to, and the other streams keep delivering.
Exercise
How does a browser learn that a server supports HTTP/3, and what happens if UDP port 443 is blocked on the network?
Show answer
It learns from an Alt-Svc response header received over HTTP/1.1 or HTTP/2, or from an HTTPS record in DNS. If the QUIC attempt on UDP 443 is blocked or times out, the browser falls back to TCP and TLS, where ALPN selects h2 or http/1.1. The page still loads, but over an older version.