---
title: "Everything I didn’t know about HTTP2 (Part 1) · Ihab Khattab"
description: "The HTTP/1.1 limits that shaped web performance: head-of-line blocking, the 6-connection cap, bundling, domain sharding, heavy headers, and extra roundtrips."
url: "https://ihabkhattab.com/blog/everything-i-didnt-know-about-http2-part-1/"
---

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

Aug 13, 2020 · 4 min read · Updated 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](https://en.wikipedia.org/wiki/Head-of-line_blocking#In_HTTP): 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™️”.

![](https://ihabkhattab.com/_astro/image-02.CefntdIb_1bgW1p.webp)

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:

Animated waterfall: Over HTTP/1.1 with one domain, the browser opens up to 6 connections. Each one carries one request at a time, so the 20 files the page needs queue up behind each other, and each request waits a full round trip before its first byte. The page loads in about 1,050 ms. [Watch it on the page](https://ihabkhattab.com/blog/everything-i-didnt-know-about-http2-part-1/).

_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](https://css-tricks.com/css-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.

Figure: The header's background color changes from #1a1a2e to #16213e: six characters in header.css. With 5 separate CSS files, a returning visitor downloads only header.css again: 2 KB, and the other files stay cached. With all of them concatenated into one bundle, the whole 40 KB bundle is downloaded again.

_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.

Animated waterfall: Sharded across two asset domains, the browser opens 12 connections and fewer files queue up. But both new domains need their own DNS lookup and connection setup first, so the files start later. The page loads in about 1,030 ms, barely faster. Over HTTP/1.1 with one domain, the browser opens up to 6 connections. Each one carries one request at a time, so the 20 files the page needs queue up behind each other, and each request waits a full round trip before its first byte. The page loads in about 1,050 ms. [Watch it on the page](https://ihabkhattab.com/blog/everything-i-didnt-know-about-http2-part-1/).

_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

```html
<!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.

```html
<!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!”.

Animated sequence diagram: HTTP/1.1: the browser asks for page.html, waits for the server to build and send it, parses it, and only then asks for style.css and script.js: a second round trip. Everything is there at 840 ms. Inlined: the server writes the CSS and JS into page.html, so one round trip brings everything, at 640 ms. But it sends them every time, even when the browser already has them cached: 120 KB for nothing. [Watch it on the page](https://ihabkhattab.com/blog/everything-i-didnt-know-about-http2-part-1/).

_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](https://ihabkhattab.com/blog/everything-i-didnt-know-about-http2-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 →](https://ihabkhattab.com/ai/)

[← All posts](https://ihabkhattab.com/blog/)
