HTTP/2 Anti-Patterns: Domain Sharding and Spriting
What you'll learn: Why optimization techniques that helped HTTP/1.1 performance actually hurt HTTP/2 performance.
The Problem with Old Tricks
In HTTP/1.1, browsers could only make a limited number of parallel connections per domain (typically 6). Developers invented clever workarounds:
- Domain sharding: Serving assets from multiple subdomains (
cdn1.example.com,cdn2.example.com) to bypass the per-domain connection limit - Spriting: Combining many small images into one large sprite sheet to reduce the number of HTTP requests
These techniques made sense when each request required a separate TCP connection and HTTP overhead.
Why These Hurt HTTP/2
HTTP/2's multiplexing allows unlimited parallel requests over a single connection. Here's what happens when you use HTTP/1.1 tricks:
Domain sharding now forces the browser to:
- Establish multiple TCP connections (instead of reusing one)
- Perform multiple TLS handshakes (expensive!)
- Split available bandwidth across connections
- Lose the benefit of header compression (HPACK works best with one connection)
Spriting causes:
- Larger initial download (users download images they might never see)
- Loss of granular caching (changing one icon invalidates the entire sprite)
- Inability to prioritize individual images
The Better Approach
With HTTP/2, serve resources from a single domain and break sprites back into individual files. The multiplexed connection handles parallelism automatically, and you gain:
- Precise caching of individual resources
- Better compression of headers
- Automatic stream prioritization
- Simpler code maintenance
Key Takeaway: HTTP/2's multiplexing makes domain sharding and image spriting counterproductive—use a single domain and serve assets as separate files to maximize performance.