What is HTTP/2?
HTTP/2 is a major revision of the HTTP protocol (standardized as RFC 7540) that introduces binary framing, multiplexing, header compression, and server push to dramatically improve web performance over HTTP/1.1.HTTP/2 vs HTTP/1.1
| Feature | HTTP/1.1 | HTTP/2 |
|---|---|---|
| Format | Text-based | Binary |
| Connections | Multiple (6-8 per host) | Single multiplexed |
| Request handling | Sequential | Parallel streams |
| Header compression | None | HPACK compression |
| Server push | Not available | Supported |
| Prioritization | None | Stream priorities |
How HTTP/2 Works
HTTP/1.1 (Head-of-Line Blocking):
Connection 1: Request A ──────────► Response A
Connection 2: Request B ──────────► Response B
Connection 3: Request C ──────────► Response C
(Multiple connections, sequential per connection)
HTTP/2 (Multiplexing):
Single Connection:
├── Stream 1: Request A ──► Response A
├── Stream 2: Request B ──► Response B
├── Stream 3: Request C ──► Response C
└── All interleaved on same connection
Key Features
Binary Framing Layer
HTTP/2 Frame Structure:
┌─────────────────────────────────────┐
│ Length (24 bits) │
├─────────────────────────────────────┤
│ Type (8 bits) │ Flags (8 bits) │
├─────────────────────────────────────┤
│ Stream Identifier (32 bits) │
├─────────────────────────────────────┤
│ Frame Payload (variable) │
└─────────────────────────────────────┘
HPACK Header Compression
| Scenario | HTTP/1.1 Headers | HTTP/2 Headers |
|---|---|---|
| First request | ~800 bytes | ~800 bytes |
| Subsequent requests | ~800 bytes each | ~20-50 bytes (indexed) |
Stream Prioritization
Priority Tree:
Root (connection)
├── CSS (weight: 256, high priority)
├── JavaScript (weight: 220)
└── Images (weight: 110, lower priority)
Server Requirements
| Server | HTTP/2 Support |
|---|---|
| nginx | 1.9.5+ |
| Apache | 2.4.17+ (mod_http2) |
| Node.js | 8.4+ (native) |
| IIS | Windows 10/Server 2016+ |
Performance Benefits
- Reduced latency: Single connection eliminates TCP handshake overhead
- Better compression: 85-90% header size reduction on repeat requests
- Parallel loading: All resources load simultaneously
- Server push: Proactively send resources before browser requests them
Best Practices
1. Enable TLS: HTTP/2 practically requires HTTPS (browsers enforce it)
2. Reduce domain sharding: Multiple domains now hurt performance
3. Stop concatenating files: Multiplexing makes bundling less necessary
4. Use server push carefully: Push only critical resources
5. Monitor performance: Verify HTTP/2 improves your specific use case
HTTP/2 delivers significant performance improvements for most websites through more efficient use of network connections.