Brotli & Compression Dictionaries
Brotli (br) beats gzip by 15–25% on JS and CSS using a built-in static dictionary of common web tokens. Compression Dictionary Transport (dcb/dcz) goes further: the browser feeds your cached app.v1.js into the decompressor so app.v2.js transfers as a tiny delta.
Payload Transfer: Gzip vs Brotli vs Dictionary Delta
Adjust bundle delta ratio and Brotli quality to observe wire bytes and compression CPU latency.
Under the Hood
Standard compression treats every hashed bundle (app.v2.js) as a brand-new stranger, forcing users to re-download 98% unchanged code. Shared dictionaries work like git diff over HTTP: the HTTP Cache supplies app.v1.js as a reference window, and the server only streams the bytes that changed.
- On the initial fetch, the server sends
Use-As-Dictionary: match="/assets/app.*.js"alongside a cacheable response. - On the next deploy, the client advertises
Available-Dictionary: :<sha256>:andAccept-Encoding: gzip, br, dcb, dczover HTTP/2 & HTTP/3. - The CDN or build pipeline compresses
app.v2.jsagainstv1and returnsContent-Encoding: dcbwithVary: Available-Dictionary.
# Response 1: register cached bundle as a dictionary
Use-As-Dictionary: match="/assets/app.*.js", id="app-v1"
Cache-Control: public, max-age=31536000, immutable
# Response 2: delta-compressed update
Content-Encoding: dcb
Vary: Available-Dictionary, Accept-EncodingProblem Genealogy
- 1996 (RFC 1952 Gzip): DEFLATE over HTTP cut text sizes dramatically, but lacked a pre-trained web vocabulary.
- 2015 (RFC 7932 Brotli): Embedded a 120 KB static dictionary of HTML/CSS/JS tokens, becoming the default for static assets, at the cost of slow level-11 encoding.
- 2024+ (RFC 9842 Compression Dictionaries): Standardized
Use-As-Dictionary, ending the curse of 1-line bugfixes invalidating 400 KB bundles.
Production Pitfalls
- Brotli quality 11 on dynamic SSR: Running max-quality Brotli on uncached HTML stalls TTFB on the origin CPU; pre-compress static files at level 11 and cap dynamic responses at level 4–5.
- Missing
Vary: Available-Dictionary: WithoutVary, a CDN caches adcbbinary diff and serves it to first-time visitors who lack the base dictionary.
- When not to use compression: Already-compressed binary formats (
woff2,avif,webp,mp4) only waste CPU cycles and can actually grow slightly when re-compressed.
Connections & Logical Next Steps
Shared dictionaries reuse cached HTTP responses and require Cache-Control + Vary headers.
Compressed streams reduce frame count and header overhead across multiplexed connections.
Vary: Accept-Encoding prevents serving a Brotli or dictionary payload to incompatible clients.