Everything I didn’t know about HTTP2 (Part 1)

4 min readUpdated May 16, 2026

What Got You Here Won’t Get You There#

Before we talk about HTTP2 we need first to know what was the problem in HTTP/1.1 that makes us need to think we need to introduce HTTP2.

When HTTP first introduced more than 20 years ago there was no intention to handle this type of rich application, AJAX…etc, and all cool stuff we have today. The most notable limitation was head-of-line blocking: a connection handles one request at a time, so a slow response holds up every request queued behind it. Browsers open more connections to get around it, but no more than 6 per origin, it was 2 connections only in the beginning. to address this and limitation comes with it we started introducing workarounds that we’ll later name it “Best Practices™️”.

Here’s a page with 20 files loading over HTTP/1.1. Watch the files queue up for a free connection, and how each request waits a full round trip before its first byte:

Loaded in –

0 connections

0 files waiting for one

  • DNS lookup and TCP+TLS setup
  • Waiting for the first byte
  • Downloading
A simulated page load: a 100 ms round trip on a 16 Mbps link. Each connection carries one file at a time, so hero.jpg holds up everything queued behind it on its connection.

Concatenation, minification, and sprites#

We have to do this as opening a new connection to download resources is a costly process and already limited (the aforementioned 6 parallel connection per origin limitation) so we will concatenate all of our assets (js, CSS and images as sprites) together and minify them to decrease the number of requests needed.

The problem with this approach is: change is costly, if you made any change for example to the minified CSS file like you change the color of the header background color, for example, you will invalidate all the CSS cache and the user will need to download this CSS file again although the change is very small compared to the change in download size. you change 6 characters and invalidate kilobytes in return for example.

The change, in header.css:background: #1a1a2e16213e

Separate files5 requests

header.css2 KB, download againlayout.css12 KB, still cachedbuttons.css6 KB, still cachedforms.css10 KB, still cachedtheme.css10 KB, still cached

2 KB to download

One bundle1 request

bundle.min.css40 KB, download again

40 KB to download

A returning visitor whose cache already has last week’s CSS. Bundling saved requests on every first visit, and cost a full re-download on every change.

Domain sharding#

An interesting thing about the 6 connections limit is: it is per origin, this means if we introduce more origins (domains) we can increase the number of connections available 💡 so we started to host our assets on domains like assets1.example.com, assets2.example.com, etc. This paid off most back when browsers allowed only 2 connections per domain: going from 2 to 4 is a big jump, going from 6 to 12 much less so.

There was a bonus too: a separate asset domain could be cookie-free, so image and script requests skipped the cookie header entirely, as long as your cookies weren’t set for the whole parent domain. More on why that matters in the next section.

The problem with this approach: every additional domain needs a new DNS lookup that the user has to wait for before the browser can download files. Every connection to it also needs its own TCP+TLS setup, which costs more round trips. And more connections don’t make the network any faster: they all share the same bandwidth.

Loaded in –

0 connections

0 files waiting for one

Version
  • DNS lookup and TCP+TLS setup
  • Waiting for the first byte
  • Downloading
The same simulated page, with its files split across assets1 and assets2. Twice the connections, but they open only after two new DNS lookups and their own TCP+TLS setup, and they share the same bandwidth. Switch to one domain to compare: sharding comes out barely faster.

Metadata#

HTTP is a stateless protocol this means we can’t know if 2 requests are by the same user or not. so we have to start using cookies; a special header that’s sent with every request we use to identify the user and may add other useful data as well. this will add additional bytes or even kilobytes to every request adding to this user agent too. the problem with this metadata is it’s static (most of the time they will be rarely changed) and not compressed data sent over the wire.

Avoidable Roundtrips#

Imagine this scenario we’ve page.html hosted in our server with some assets

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
    <title>Page</title>
  </head>
  <body>
    <img src="./Picaso.png" alt="Marawan Pablo" />
    <script src="script.js"></script>
  </body>
</html>

Although the server knows that this page.html page will request style.css, script.js, and Picaso.png files. you have no way to give a hint to the server: “when the client asks for page.html send these 3 files along with it.” although all files are on the server in the same place and it knows this HTML page will request these files.

Again we introduce a new workaround we started to inline resources, this means concatenate content of these files minify them (encode them in Base64 in case of images) so we can send them all together in the same response by writing them directly to the HTML file, this removed the need to make additional roundtrip we already know about beforehand.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <style>
      /**
       * initial inlined CSS goes here
       */
    </style>
    <title>Page</title>
  </head>
  <body>
    <img alt="Marawan Pablo" src="data:image/png;base64,....==" />
    <script>
      /**
       * initial inlined javascript goes here
       */
    </script>
  </body>
</html>

But again this comes with a problem, we are sending the same data of assets over the wire again, as every time the browser requests HTML pages that uses some of the assets it has no way to utilize the idea it already receives this data before, we lost what we could gain by caching these assets. also in HTTP/1.1, we’ve no way other than cache mechanism to tell the server “we already received this data don’t send it again, please!”.

Everything there at –

Sent for nothing 0 KB

Approach
A simulated load with a 100 ms trip each way and 250 ms for the server to build the page. Inlining saves the second round trip, but tick “already cached” to see what it costs on the next visit.

In part 2 I talk about what HTTP2 actually fixed with multiplexing, header compression, and binary framing, which of these old “Best Practices™️” became unnecessary, and what happened to Server Push, the feature that was supposed to solve the roundtrip problem.

I wrote this in 2020, before I used AI tools. When I moved it here, Claude reviewed it and fixed some parts. How I use AI →

← All posts