Tiered Cache-Control Strategy
Effective caching separates versioned static assets (CSS, JS, fonts, images with content hashes in their filenames) from HTML documents whose URLs remain constant:
| Resource Type | Recommended Cache-Control Header |
Behavior |
|---|---|---|
Hashed Assets (/app.8f3a1c.css) |
public, max-age=31536000, immutable |
Cached for 1 year; browser skips conditional revalidation completely |
HTML Pages (/guides/...) |
public, max-age=0, s-maxage=3600, stale-while-revalidate=86400 |
Edge CDN serves cached HTML instantly while refreshing in the background |
Search / JSON Indexes (/search.json) |
public, max-age=300, stale-while-revalidate=3600 |
Fast client autocomplete with 5-minute freshness window |
Static Precompression with Brotli and Zstd
Text assets (HTML, CSS, JS, JSON, SVG) compress dramatically better with Brotli (br) and Zstandard (zstd) than legacy Gzip:
- Precompress at Build Time: Generate
.br(quality 11) and.zstartifacts during your CI build so your web server or CDN serves maximum-compression payloads with zero per-request CPU overhead. - Always Set
Vary: Accept-Encoding: Ensures intermediate proxies never serve a Brotli-encoded response to a client that only requested Gzip.
Connection Coalescing on HTTP/2 & HTTP/3
Serving static assets from the same origin (or a wildcard-covered subdomain sharing the same TLS certificate and IP) allows browsers to reuse a single multiplexed HTTP/3 connection rather than paying extra DNS and TLS handshakes.