HTTP/1.1: one request at a time
HTTP/1.1 (1997, still everywhere) is plain text over a TCP connection, and a connection carries one request at a time: send a request, wait for the whole response, then send the next.
Early HTTP opened a new connection for every request. HTTP/1.1 made keep-alive the default: after a response, the connection stays open and the next request reuses it, skipping the TCP and TLS handshakes. On a mobile network that saves two round trips, often 100 to 300 ms, per request.
The remaining problem is waiting in line. If the first response is slow (a big image, a slow database query), everything queued behind it on that connection waits. This is head-of-line blockingHead-of-line blockingWhen the first item in a queue is slow and everything behind it has to wait.Open in glossary →: the request at the front of the line holds up the rest.
Browsers work around it by opening several connections to the same host, usually six. A page with 60 small images on one host downloads them six at a time. Web developers built tricks around that limit:
- Bundling: combine all JavaScript into one big file and all CSS into another.
- Sprites: put many small icons into one image and show parts of it.
- Domain sharding: spread files over
img1.shop.example,img2.shop.example… to get six connections per name.
They all reduce the number of requests, because with HTTP/1.1 every request costs a place in a short queue.
- Wire format: text start line and headers,
\r\nseparators, bodies framed byContent-Lengthor chunked encoding. Header names and values repeat in full on every request (cookies and tokens can be several KB per request). - Keep-alive is default in 1.1 (
Connection: closeopts out). Servers and proxies close idle connections after their own timeout; clients that reuse a just-closed connection get a reset (retry idempotent requests). - Pipelining (sending several requests without waiting) was in the spec but responses must come back in order, so one slow response still blocks the rest, and buggy proxies broke it. Browsers never enabled it by default.
- Per-host connection limits: about 6 in browsers; each connection pays its own handshakes and its own TCP slow start, and competes with the others for bandwidth.
- HTTP/1.1 is still the norm between many internal services, load balancers and back ends, and for
curl-style tools. It’s simple to debug and has no stream-level complexity, which is why it survives.
Predict the output
curl downloads the same URL twice in one command. What does the verbose output say before the second request?
curl -sv -o /dev/null -o /dev/null https://example.com/ https://example.com/ 2>&1 \
| grep -iE 'Connected to|re-using|using HTTP'curl keeps the connection open after the first response and reuses it, so the second request skips DNS, the TCP handshake and the TLS handshake. Apps get the same benefit only if they reuse one HTTP client object: its connection pool is where open connections live. (Here the server also negotiated HTTP/2, so curl could even send requests in parallel over that one connection.)
GET /api/orders?page=2 HTTP/1.1
Host: shop.example
Accept: application/json
Accept-Encoding: gzip, br
Authorization: Bearer eyJhbGciOi...
Connection: keep-alive
HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: gzip
Content-Length: 1834
Keep-Alive: timeout=5
(1,834 bytes of gzip-compressed JSON)Worked example: a product page over HTTP/1.1
A product page needs the HTML, one CSS file, one JavaScript bundle and 12 product images, all from shop.example. The round trip is 100 ms, and each file takes about one round trip to download.
- First connection. DNS, the TCP handshake and the TLS handshake: about 300 ms before the first byte of the request.
- The HTML. Request and response on that connection: 100 ms more. Now the browser knows what else it needs.
- More connections. It opens up to five more connections to the same host (each paying its own handshakes, in parallel) and starts the CSS and JavaScript.
- Images in waves. Twelve images over six connections: two waves of six, about 200 ms, if nothing is slow.
- One slow image. If one image takes a second (a big file, a slow server), the requests queued behind it on that connection wait. The page looks half-loaded.
- Total. Roughly 700 to 800 ms for a small page, mostly spent waiting for round trips, not downloading.
That’s the situation HTTP/2 was designed to fix: fewer connections, no queue per connection.
Deep diveWhich HTTP/1.1 optimizations to undoInterview favorite
“We’re moving to HTTP/2. Which front-end performance tricks still make sense?” The tricks existed because requests were expensive; with multiplexing they’re cheap, so some tricks now hurt.
- Domain sharding: remove it. Extra hostnames mean extra DNS lookups, TCP and TLS handshakes, and separate congestion windows that compete. With HTTP/2, one connection does better. (Browsers can coalesce connections across names that share an IP and certificate, which partly rescues old sharding.)
- Sprites and inlining: mostly remove. One huge sprite is cached and invalidated as a whole, and inlined images or CSS can’t be cached separately. Individual files cache better and cost little to request.
- Bundling: keep, but smaller. One giant bundle means a one-line change invalidates everything in the cache. Split per route and per rarely changing vendor code. Very many tiny files still have per-request overhead (headers, server work, priority handling), so “hundreds of unbundled modules” isn’t free either.
- Still matters: compression, caching headers, fewer sequential round trips (a request chain where each call needs the previous result can’t be parallelized by any protocol), image sizes, and putting the server close to users.
For mobile APIs the same logic applies: under HTTP/2, a few parallel small requests are fine, and a screen that waits for five calls one after another is slow on every version.
- Text protocol; one request in flight per connection; keep-alive default; pipelining unusable (in-order responses).
- About 6 connections per host in browsers, each with its own handshakes and slow start.
- Sharding, sprites and inlining were HTTP/1.1 workarounds; under HTTP/2 remove sharding and sprites, keep moderate bundling.
- Sequential request chains are slow on every version.
curl -sv --http1.1 -o /dev/null https://example.com/ 2>&1 | grep -i alpn
# * ALPN: curl offers http/1.1
# * ALPN: server accepted http/1.1Check this part
What does keep-alive save?
Why do browsers open several connections to one host under HTTP/1.1?
Why was HTTP/1.1 pipelining never enabled by default in browsers?
After moving to HTTP/2, what should happen to domain sharding?