HTTP Mastery: From 1.1 to 3
A comprehensive guide to HTTP's evolution from 1.1 through HTTP/3. Understand multiplexing, header compression, server push, QUIC's connection migration, and when to use WebSocket vs SSE vs HTTP/2.
HTTP is the language of the web. Every page load, every API call, every image request flows through it. For most of the web's history, HTTP/1.1 was the lingua franca — functional, widely understood, and deeply flawed in ways that only became apparent as web complexity grew.
Understanding how HTTP evolved — and why HTTP/2 and HTTP/3 were designed the way they were — gives you a mental model for making better decisions about caching, request batching, CDN configuration, and real-time architecture.
Part 3 covers Chapters 9–17 of High Performance Browser Networking.
Chapter 9: A Brief History of HTTP
HTTP was designed in 1989 by Tim Berners-Lee at CERN. The original goal was simple: a protocol for sharing hypertext documents between researchers. Three decades later, it carries 4K video, multiplayer games, and real-time financial data.
HTTP/0.9 → HTTP/1.0 → HTTP/1.1
HTTP/0.9 (1991): One-line GET requests, HTML-only responses, connection closed after every response. Barely a protocol.
HTTP/1.0 (1996): Added headers, status codes, content types, and POST. Still closed the TCP connection after every response — meaning a page with 10 images required 11 TCP handshakes.
HTTP/1.1 (1997): The version that defined the modern web for 18 years:
- Persistent connections (keep TCP alive across requests)
- Chunked transfer encoding (stream without knowing total size)
- Cache headers (
Cache-Control,ETag,Last-Modified) - Virtual hosting (
Hostheader — multiple domains per IP) - HTTP pipelining (send multiple requests without waiting for responses)
HTTP/1.1 was remarkably successful. But it had structural limitations that became impossible to ignore as web pages grew from 10KB to 10MB of assets.
<PaywallGate partNumber={3}>Chapter 10: HTTP/1.1 — Head-of-Line Blocking
HTTP/1.1's persistent connections helped, but the protocol has a fundamental structural flaw: within a single connection, requests must be processed in order.
If request 3 is slow (a large image, a slow database query), requests 4 and 5 wait behind it — even if they could be served instantly. This is head-of-line blocking.
HTTP pipelining was supposed to solve this, but server implementations were buggy enough that browsers disabled it by default. The result: browsers open 6 parallel TCP connections per origin to get parallelism.
The Hidden Costs of 6 Connections
Six parallel connections sounds like a solution. It's actually a band-aid with serious side effects:
- 6 TCP handshakes (6 RTTs of overhead on cold start)
- 6 TLS handshakes (6 more RTTs for HTTPS)
- 6 independent slow-start phases — each congestion window starts small
- 6 streams competing for the same bandwidth, fragmenting the congestion window
Ironically, more connections can slow things down by fragmenting available bandwidth into smaller streams that each throttle independently. A single connection with a large congestion window is more efficient than six connections each with a tiny window.
Domain Sharding: The Workaround That Backfired
To get more than 6 connections, developers split static assets across multiple domains: static1.example.com, static2.example.com. This forces browsers to open 6 connections per domain, enabling 18 or more parallel connections.
The technique is called domain sharding and it was once considered best practice. It has serious costs:
- Additional DNS lookups per domain (each adds latency)
- More TCP/TLS connection overhead
- More memory usage in both client and server
- Actively harmful under HTTP/2, which prefers a single connection
HTTP/1.1 Optimization Techniques (and Their HTTP/2 Replacements)
| HTTP/1.1 Technique | Problem It Solves | HTTP/2 Replacement |
|---|---|---|
| Bundle all JS into one file | Reduce connection count | Stream multiplexing |
| CSS sprites | Reduce image requests | Individual image files |
| Domain sharding | More parallel connections | Single connection, multiplexed |
| Inline small assets as Data URIs | Avoid separate requests | HTTP/2 server push |
| Concatenate CSS files | Reduce request count | Individual files, multiplexed |
Notice the pattern: HTTP/1.1 optimizations often conflict with HTTP/2 best practices. Migrating to HTTP/2 sometimes requires undoing years of HTTP/1.1 optimization work.
Chapter 11: HTTP/2 — Multiplexing Changes Everything
HTTP/2 (RFC 7540, 2015) was designed to eliminate HTTP/1.1's structural limitations while maintaining backward compatibility with existing HTTP semantics. It's a binary protocol that runs over the same TCP connection but completely restructures how data flows.
The Five Core Features
1. Binary Framing
HTTP/1.1 is text-based (GET /path HTTP/1.1\r\n). HTTP/2 is binary — requests and responses are split into frames which are multiplexed over a single connection. Binary framing is more efficient to parse and less error-prone than text parsing.
2. Stream Multiplexing
Multiple requests and responses are interleaved over a single TCP connection. Each logical request/response pair is a "stream" with a unique ID. Streams are independent — a slow stream doesn't block fast ones.
3. Header Compression (HPACK)
HTTP headers are heavily repetitive. Every request sends Accept-Language, User-Agent, Cookie, and dozens of other headers — most identical to the previous request. HPACK compresses headers using a shared table, reducing header overhead by 85–95%.
A first request might send 800 bytes of headers. Subsequent requests to the same server might send 50 bytes.
4. Stream Prioritization
Clients can signal which streams matter more. The browser can say: "give stylesheets priority over images while rendering the above-the-fold content." Servers that respect prioritization can deliver critical resources first.
5. Server Push
Servers can proactively send resources the client will need before they're requested. When a client fetches index.html, the server can immediately push styles.css and app.js without waiting for the browser to parse the HTML and discover those resources.
Note: Server push was widely misused and many implementations found it hurt more than it helped. It's deprecated in HTTP/3.
<CodePlayground title="Checking HTTP Protocol via Performance API" language="javascript" code={`// Resource Timing API reveals which protocol was used const observer = new PerformanceObserver((list) => { list.getEntries().forEach((entry) => { const resource = entry; console.log({ url: resource.name, protocol: resource.nextHopProtocol, // 'h2' = HTTP/2, 'h3' = HTTP/3, 'http/1.1' = legacy ttfb: resource.responseStart - resource.requestStart, totalTime: resource.duration, }); }); }); observer.observe({ entryTypes: ['resource', 'navigation'] });
// Also visible in Chrome DevTools: // Network tab → right-click column header → Protocol`} />
HTTP/2 and JavaScript Bundling — The Nuanced Answer
One of the most debated questions after HTTP/2's release: should you still bundle JavaScript? The answer is nuanced.
Arguments for unbundled (many small files):
- HTTP/2 eliminates per-request connection overhead
- Cache granularity — changing one module doesn't invalidate everything
- Parallel loading of independent modules
Arguments for bundled (fewer large files):
- Better compression ratios (Brotli/gzip work better on larger files with more repetition)
- Parse time: 1×100KB bundle parses faster than 100×1KB modules (V8 overhead per file)
- Tree-shaking across the whole bundle eliminates dead code
Modern recommendation: Code-split at route boundaries, bundle within routes. Each route gets its own bundle. Core framework code is a shared chunk cached across routes. This balances cache granularity with compression efficiency.
The HTTP/2 TCP Problem
HTTP/2 solved head-of-line blocking at the HTTP layer — but TCP doesn't know about HTTP streams. TCP sees one byte stream. If a single packet is lost, all HTTP/2 streams stall until TCP retransmits that packet.
On reliable connections (wired, good WiFi), this is rarely a problem. On lossy connections (2% packet loss is common on mobile), HTTP/2 can perform worse than HTTP/1.1 with multiple connections — because HTTP/1.1 would only block one of its 6 connections, while HTTP/2 blocks everything.
This fundamental limitation motivated HTTP/3.
Chapter 12: HTTP/3 and QUIC
HTTP/3 (RFC 9114, 2022) replaces TCP with QUIC — a transport protocol built entirely on UDP that provides all of TCP's reliability without its head-of-line blocking limitation.
What QUIC Solves
Per-stream reliability: QUIC maintains independent reliability per stream. A lost packet only blocks the stream it belongs to, not every other stream on the connection. This is the killer feature.
0-RTT connection establishment: On repeat connections, the client can send HTTP requests in the very first packet — before completing a handshake. The server issued a session token on the previous connection; the client presents it to resume immediately.
Connection migration: When you switch from WiFi to 4G mid-session, your IP address changes. TCP connections break — they're tied to the IP 4-tuple (src IP, src port, dst IP, dst port). QUIC connections use a Connection ID instead. When your IP changes, the connection migrates transparently. No reconnection, no dropped requests.
Modern congestion control: QUIC implements BBR (Bottleneck Bandwidth and Round-trip propagation time) and other modern algorithms by default, rather than TCP's decades-old Reno/CUBIC.
<CodePlayground title="nginx: Enable HTTP/2 and HTTP/3" language="nginx" code={`# nginx.conf — Full HTTP/2 + HTTP/3 setup server { listen 443 ssl; # HTTP/1.1 + HTTP/2 over TCP listen 443 quic reuseport; # HTTP/3 over QUIC/UDP
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
ssl_protocols TLSv1.3; # Required for HTTP/3
http2 on;
# Advertise HTTP/3 availability to clients
add_header Alt-Svc 'h3=":443"; ma=86400';
add_header Strict-Transport-Security "max-age=63072000";
location / {
root /var/www/html;
# Aggressive caching for static assets
add_header Cache-Control "max-age=31536000, immutable";
}
}`} />
HTTP/3 Adoption Reality
As of 2024, HTTP/3 is supported by:
- All major browsers (Chrome, Firefox, Safari, Edge)
- Cloudflare, Fastly, AWS CloudFront (all enabled by default)
- ~28% of the top 1M websites
For most teams, enabling HTTP/3 requires no application changes — it's negotiated at the protocol layer. If you're running behind Cloudflare or a modern CDN, it may already be enabled. Check your network panel for h3 protocol values.
<Quiz question="A user's phone switches from WiFi to 4G mid-request. Which protocol handles this without dropping the connection?" options={[ "HTTP/1.1 — persistent connections survive network changes", "HTTP/2 — multiplexing maintains stream state", "HTTP/3 / QUIC — connection IDs survive IP address changes", "WebSocket — full-duplex connections are network-agnostic" ]} correct={2} explanation="QUIC uses Connection IDs instead of the TCP 4-tuple (src/dst IP + port). When the client's IP changes during network handoff, the QUIC connection migrates transparently — the server recognizes the Connection ID and continues the session. TCP, HTTP/1.1, and HTTP/2 all break on IP change." />
Chapter 13: Optimizing Application Delivery
Before reaching for WebSocket or custom protocols, HTTP itself — used well — handles most real-time-adjacent use cases.
The Caching Hierarchy
| Layer | Mechanism | Scope | Latency |
|---|---|---|---|
| Memory cache | Browser in-memory | Single tab, single session | 0ms |
| Disk cache | Browser disk | Single user, across sessions | 1–5ms |
| Service Worker | Programmatic cache | Single user, offline-capable | 1–10ms |
| CDN edge | Shared cache | All users, geographic | 5–50ms |
| Origin server | Response | All users | Full RTT |
Getting a resource from the memory cache is 100–1000× faster than a network request. Your caching strategy is one of the highest-leverage performance improvements available.
Resource Hints
Tell the browser about resources it will need before it discovers them:
<CodePlayground title="Resource Hints for Faster Loading" language="html" code={`<!-- Preconnect: Establish TCP+TLS before the request -->
<!-- Use for third-party origins you know you'll need --> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://api.example.com" crossorigin> <!-- DNS Prefetch: Resolve DNS early (lower priority than preconnect) --> <link rel="dns-prefetch" href="https://cdn.example.com"> <!-- Preload: Fetch a specific resource at high priority --> <!-- Critical for fonts, hero images, above-fold CSS --> <link rel="preload" href="/fonts/inter.woff2" as="font" crossorigin> <link rel="preload" href="/hero.webp" as="image"> <!-- Prefetch: Fetch for next navigation (low priority, idle time) --> <link rel="prefetch" href="/dashboard.js"> <!-- Each has a cost — don't preconnect/preload everything -->`}/>
Chapter 14: WebSocket — Full-Duplex Real-Time
HTTP's request-response model breaks down for real-time applications: live chat, collaborative editing, multiplayer games, live dashboards. The solution: WebSocket.
WebSocket vs HTTP: The Key Difference
HTTP: Client initiates → Server responds → Done. One request, one response.
WebSocket: Client initiates upgrade → Both sides can send at any time → Connection stays open indefinitely.
The WebSocket handshake begins as an HTTP/1.1 request:
<CodePlayground title="WebSocket HTTP Upgrade Handshake" language="http" code={`# Client request GET /live-feed HTTP/1.1 Host: example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Version: 13
Server response (101 = Switching Protocols)
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
After this, the TCP connection is no longer HTTP.
Both sides send framed WebSocket messages freely.`}
/>
<CodePlayground title="WebSocket Client and Server (Node.js)" language="javascript" code={`// Browser client const ws = new WebSocket('wss://api.example.com/ws');
ws.onopen = () => ws.send(JSON.stringify({ type: 'subscribe', channel: 'prices' })); ws.onmessage = (e) => updateUI(JSON.parse(e.data)); ws.onerror = (err) => console.error('WebSocket error', err); ws.onclose = (e) => console.log('Closed:', e.code, e.reason);
// Server (Node.js with 'ws' package) import { WebSocketServer } from 'ws'; const wss = new WebSocketServer({ port: 8080 });
wss.on('connection', (socket) => { socket.on('message', (data) => { const msg = JSON.parse(data.toString()); if (msg.type === 'subscribe') { // Add to subscription list, push updates subscriptions.add({ socket, channel: msg.channel }); } });
socket.on('close', () => subscriptions.delete(socket)); });`} />
WebSocket vs. Server-Sent Events vs. HTTP/2 Push
| Mechanism | Direction | Protocol | Best For |
|---|---|---|---|
| WebSocket | Bidirectional | Custom framing over TCP | Chat, games, collaborative editing |
| Server-Sent Events (SSE) | Server → Client only | HTTP/1.1 or HTTP/2 | Live feeds, notifications, dashboards |
| HTTP/2 Push | Server → Client only | HTTP/2 | Predictive resource preloading |
| HTTP Long Polling | Server → Client (batched) | HTTP/1.1 | Legacy browser support |
Server-Sent Events are dramatically underused. For server-to-client streaming, SSE is simpler than WebSocket and has built-in reconnection:
<CodePlayground title="Server-Sent Events — The Underused Alternative" language="javascript" code={`// Browser — EventSource handles reconnection automatically const stream = new EventSource('/api/live-prices');
stream.onmessage = (e) => { const { symbol, price } = JSON.parse(e.data); updateTickerUI(symbol, price); };
// Named events (server sends: event: price-update) stream.addEventListener('price-update', (e) => { /* ... */ }); stream.onerror = () => console.log('Reconnecting...'); // Auto-reconnects
// Server (Node.js / Express) app.get('/api/live-prices', (req, res) => { res.setHeader('Content-Type', 'text/event-stream'); res.setHeader('Cache-Control', 'no-cache'); res.setHeader('Connection', 'keep-alive'); res.flushHeaders(); // Send headers immediately
const timer = setInterval(() => { // SSE format: "data: <content>\n\n" const payload = JSON.stringify({ symbol: 'AAPL', price: 189.50 }); res.write(`data: ${payload}\n\n`); }, 1000);
req.on('close', () => clearInterval(timer)); });`} />
Chapter 17: WebRTC — Peer-to-Peer in the Browser
WebRTC enables capabilities impossible with traditional client-server models: direct browser-to-browser communication for audio, video, and data — without a server in the data path after connection setup.
The Three Core APIs
MediaStream API: Capture microphone, webcam, and screen.
const stream = await navigator.mediaDevices.getUserMedia({
video: { width: 1280, height: 720, frameRate: 30 },
audio: { echoCancellation: true, noiseSuppression: true }
});
videoElement.srcObject = stream;
RTCPeerConnection API: Establish encrypted peer-to-peer connections with ICE negotiation, codec selection, and bandwidth adaptation.
RTCDataChannel API: Low-latency bidirectional data channels with optional reliability (unreliable channels behave like UDP, reliable like TCP).
ICE and NAT Traversal
The hardest problem in WebRTC: most devices are behind NAT and aren't directly reachable from the internet. ICE (Interactive Connectivity Establishment) solves this through progressive fallback:
<CodePlayground title="WebRTC ICE Candidate Gathering" language="javascript" code={`// Both peers must exchange ICE candidates via a signaling server // (WebRTC specifies the peer protocol but not the signaling mechanism)
const pc = new RTCPeerConnection({ iceServers: [ { urls: 'stun:stun.l.google.com:19302' }, // Free STUN { urls: 'turn:turn.example.com:443', // Your TURN server username: 'user', credential: 'secret', } ] });
// ICE candidates are gathered asynchronously pc.onicecandidate = (e) => { if (e.candidate) { signalingServer.send({ type: 'ice', candidate: e.candidate }); } };
// ICE tries in order: // 1. Host candidates: direct LAN connection // 2. Server-reflexive (STUN): NAT-punched direct connection // 3. Relay (TURN): proxied through TURN server (~30% of connections)`} />
Plan for ~30% of WebRTC connections requiring TURN relay. TURN servers carry all traffic for those sessions — budget for bandwidth accordingly (video calls at 720p use ~1–2 Mbps per participant).
Key Takeaways
After completing all three parts of this series:
- HTTP/1.1's head-of-line blocking drove a decade of workarounds (bundling, sprites, domain sharding) that HTTP/2 made obsolete — and sometimes harmful
- HTTP/2 multiplexing solves the HTTP layer but not TCP's layer — packet loss still blocks all streams
- HTTP/3 / QUIC solves the TCP problem with per-stream reliability over UDP, plus 0-RTT and connection migration
- WebSocket is right for bidirectional, high-frequency real-time; SSE is simpler and underused for server-push-only use cases
- WebRTC enables direct peer-to-peer audio/video/data — no server in the media path after ICE negotiation
- Enable HTTP/3 on your CDN (Cloudflare, Fastly) — likely one checkbox
- Undo domain sharding — it hurts HTTP/2 and HTTP/3
- Switch from sprites to individual images — HTTP/2+ handles the request volume
- Adopt SSE for server-to-client streaming instead of WebSocket (simpler, works through HTTP/2)
- Add resource hints —
preconnectfor third-party origins,preloadfor critical fonts and hero images - Audit your Cache-Control — static assets should use
immutablewith content hashing </CalloutBox>
Series Complete
You've now covered the entire stack from physics to application protocols:
- Part 1: Latency floors, TCP slow start, UDP trade-offs, TLS 1.3
- Part 2: WiFi contention, mobile network tiers, wireless optimization
- Part 3: HTTP evolution, HTTP/2 multiplexing, HTTP/3 QUIC, real-time APIs
The book High Performance Browser Networking by Ilya Grigorik goes much deeper on each topic — it's freely available at hpbn.co and worth reading in full.
</PaywallGate>