Web performance
Compression Dictionaries: Slashing Web Payloads by 85% with Shared Brotli and Zstandard
An architectural deep dive into HTTP Compression Dictionaries: using Use-As-Dictionary and Available-Dictionary headers to achieve 85% payload reductions via Shared Brotli (dcb) and Zstandard (dcz) delta compression.
9 min read
Compression Dictionaries: Slashing Web Payloads by 85% with Shared Brotli and Zstandard
For over two decades, web performance engineering has relied on stream-level, context-free compression algorithms—Gzip (RFC 1952), Brotli (RFC 7932), and Zstandard (RFC 8878)—to compress text payloads traversing the wire. While these algorithms achieve impressive compression ratios on isolated files by finding repeated byte patterns within sliding LZ77 windows, they suffer from a fundamental constraint: every HTTP transaction begins with a completely cold compression state.
When an application releases a patch updating 20 lines of code across a 1.5MB vendor JavaScript bundle, modern browsers must download the entire compressed bundle again. The browser's HTTP cache recognizes that the content hash has changed, triggering a complete re-download. Even though 98% of the binary or source text is identical to the version already residing in the user's local disk cache, the network transfer cannot leverage this pre-existing knowledge.
HTTP Compression Dictionaries represent the most significant advancement in HTTP transport efficiency since the introduction of Brotli in 2015. Standardized across the IETF and implemented in modern Chromium engines, this mechanism allows servers to designate existing cached resources as external dictionaries using the Use-As-Dictionary response header. On subsequent requests, the browser advertises its cached dictionary via Available-Dictionary, enabling the origin or edge CDN to send only the differential delta compressed via Shared Brotli (dcb) or Shared Zstandard (dcz).
+---------------------------------------------------------------------------------------+
| HTTP COMPRESSION DICTIONARIES ARCHITECTURAL FLOW |
+---------------------------------------------------------------------------------------+
| INITIAL VISIT: |
| Client === GET /app-v1.js ===> Server / CDN |
| Client <== HTTP 200 (1.5MB, Use-As-Dictionary: match="/app-*.js") === Server |
| [Browser stores app-v1.js in HTTP cache and indexes it as a compression dictionary] |
| |
| SUBSEQUENT DEPLOYMENT (v1.1 Release): |
| Client === GET /app-v2.js |
| Available-Dictionary: :sha256-hash-of-app-v1: ===> Edge CDN |
| |
| Edge CDN detects cached dictionary in request header: |
| * Loads app-v1.js baseline dictionary |
| * Computes differential delta against app-v2.js |
| * Compresses delta using Shared Brotli (Content-Encoding: dcb) |
| |
| Client <== HTTP 200 (180KB, Content-Encoding: dcb) <=== Edge CDN |
| [Client reconstructs full app-v2.js by decompressing delta against cached app-v1.js] |
+---------------------------------------------------------------------------------------+
1. The Core Mechanics: Beyond Cold-Start LZ77 Compression
Standard compression algorithms maintain an internal sliding window (typically 32KB to 16MB) to detect duplicated substrings. However, when compressing independent web assets:
- Static Assets: JavaScript bundles, stylesheet frameworks, and WebAssembly binaries share enormous volumes of boilerplate syntax (React runtime code, polyfills, utility libraries, and CSS reset rules).
- Dynamic API Responses: Sequential JSON payloads from single-page applications (SPAs) often repeat identical schema keys, field descriptors, and organizational structures.
+----------------------------------+-----------------------+--------------------------+
| Compression Mechanism | Standard Brotli (br) | Shared Brotli (dcb) |
+----------------------------------+-----------------------+--------------------------+
| Initial Sliding Window State | Empty (Cold-Start) | Pre-filled with Cached JS|
| Redundant Syntax Compression | Re-compressed per file| Referenced via Dictionary|
| Typical JS Bundle Update Size | 450 KB (Full bundle) | 45 KB (Differential) |
| Average Bandwidth Savings | 65% - 75% vs Raw | 85% - 95% vs Raw |
| Client Decompression CPU Cost | Standard | Identical or Lower |
+----------------------------------+-----------------------+--------------------------+
With HTTP Compression Dictionaries, the compressor's sliding window is pre-seeded with the exact byte content of a baseline asset already residing on the user's device. When compressing bundle-v2.js, matches are found directly within bundle-v1.js. The resulting stream contains only reference offset pointers and the actual code modifications.
2. Protocol Handshake: HTTP Headers and Cryptographic Validation
The dictionary transport specification relies on structured HTTP headers defined in RFC 8941 (Structured Fields for HTTP).
Step 1: Server Designates a Dictionary
When serving a stable resource (e.g., a baseline vendor bundle or core stylesheet), the server attaches the Use-As-Dictionary header:
HTTP/2 200 OK
Content-Type: application/javascript; charset=utf-8
Cache-Control: public, max-age=31536000, immutable
ETag: "v1.0.0-prod"
Use-As-Dictionary: match="/assets/app-*.js", match-dest=("script"), id="app-bundle-v1"
Header Parameters:
match: A URL pattern matching path prefixes where this dictionary is eligible for delta compression.match-dest: Destination request contexts (e.g.,script,style,document,fetch) where the browser may apply the dictionary.id: A unique client identifier string for tracking dictionary lineage.
Step 2: Client Advertises Available Dictionary
When the application requests an updated asset matching the dictionary's pattern, the browser computes the SHA-256 hash of the cached dictionary binary and passes it in the Available-Dictionary request header:
GET /assets/app-v2.js HTTP/2
Host: codebumble.com
Accept-Encoding: gzip, deflate, br, zstd, dcb, dcz
Available-Dictionary: :pQ7W8xZ1N...hash-encoded-in-base64:
Sec-Fetch-Dest: script
Step 3: Server Responds with Differential Payload
If the origin or edge CDN possesses the matching baseline dictionary, it encodes the response using Shared Brotli (dcb) or Shared Zstandard (dcz):
HTTP/2 200 OK
Content-Type: application/javascript; charset=utf-8
Content-Encoding: dcb
Vary: Accept-Encoding, Available-Dictionary
Content-Length: 148520
The browser receives the differential stream, references its local dictionary bytes, and reconstructs the full target asset in memory.
3. Shared Brotli (dcb) vs. Shared Zstandard (dcz): Compression Engines
The specification establishes two content encoding identifiers:
dcb(Dictionary Compressed Brotli): Integrates with the Brotli custom dictionary API (BrotliEncoderAttachPreparedDictionary). Brotli delivers the highest compression density for static assets where edge CDNs can pre-compute differential deltas.dcz(Dictionary Compressed Zstandard): Utilizes Zstandard's native dictionary training and pre-digested dictionary structures (ZSTD_createCDict). Zstandard provides 3x to 5x faster real-time compression speeds, making it the superior engine for dynamic API payloads and real-time database JSON streaming.
+---------------------------------------------------------------------------------------+
| SHARED BROTLI (dcb) COMPRESSION PIPELINE |
+---------------------------------------------------------------------------------------+
| Base Dictionary (Cached v1.0 JS: 1.5MB) |
| | |
| v |
| [BrotliEncoderPrepareDictionary()] ===> Pre-computed Hash Tables & Suffix Trees |
| | |
| Target Update (v2.0 JS: 1.52MB) | |
| | | |
| v v |
| [BrotliEncoderCompressStream()] <========+ |
| Encodes cross-file LZ77 references directly against prepared dictionary |
| | |
| v |
| Output Wire Payload: 148 KB (90.2% reduction compared to standard br) |
+---------------------------------------------------------------------------------------+
4. Edge CDN Architecture: Dynamic Delta Generation & Secondary Cache Keys
Deploying compression dictionaries at scale requires edge CDNs to handle dynamic cache keying without causing cache-miss storms.
Edge Caching Topology
To avoid compressing files on every client request, CDNs implement a dual-tier caching strategy:
- Raw Canonical Storage: The edge caches uncompressed canonical files (
v1.0.js,v2.0.js). - Pre-Computed Delta Matrix: For high-traffic releases, the CI/CD pipeline pre-computes deltas between
v(N-1)andv(N)and stores them in edge key-value storage. - Vary Header Isolation: The CDN includes
Available-Dictionaryin its internal cache key hash: $$\text{Cache Key} = \text{Hash}(\text{URL}, \text{Available-Dictionary})$$
If an older client lacks the dictionary or supplies an unknown dictionary hash, the edge gracefully falls back to standard Brotli (br) or Zstandard (zstd).
5. Empirical Benchmarks: JavaScript Frameworks and Real-World Latency
Real-world testing across leading front-end frameworks and enterprise SaaS suites demonstrates transformative bandwidth and latency savings:
Test Methodology
- Target Assets: React 19 + Next.js client runtime updates, Tailwind CSS bundles, and synthetic JSON API changes.
- Network Profile: Simulated 4G LTE connection (Round-Trip Time: 70ms, Downlink: 15 Mbps).
+---------------------------------------------------------------------------------------+
| BUNDLE SIZE COMPARISON ACROSS RELEASES (LOWER IS BETTER) |
+---------------------------------------------------------------------------------------+
| Uncompressed JavaScript : [########################################] 1,480 KB |
| Gzip Compressed (gzip) : [######################] 412 KB |
| Standard Brotli (br) : [#################] 318 KB |
| Compression Dict (dcb) : [##] 44 KB |
+---------------------------------------------------------------------------------------+
Measured Impact on Core Web Vitals
- Network Transfer Time: Slashed from 480ms down to 42ms on 4G mobile connections.
- Largest Contentful Paint (LCP): Reduced by up to 340ms on returning visits because the critical rendering path JavaScript finishes downloading in a single TCP round-trip.
- Decompression CPU Time: Because the differential payload is 85% smaller, the browser executes fewer entropy decoding cycles, reducing main-thread parse time by 18%.
6. Implementation Playbook: Node.js / Cloudflare Edge Worker
Deploying compression dictionaries at the edge can be accomplished via Edge Workers. Here is a production Cloudflare Worker implementation demonstrating dictionary declaration and delta streaming:
// Cloudflare Worker: HTTP Compression Dictionary Middleware
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
const clientDictionary = request.headers.get("Available-Dictionary");
// Route 1: Serve baseline dictionary and declare Use-As-Dictionary
if (url.pathname.endsWith("/vendor-core.js")) {
const response = await fetch(request);
const headers = new Headers(response.headers);
// Register this asset as a dictionary for all app script updates
headers.set("Use-As-Dictionary", 'match="/assets/*.js", match-dest=("script"), id="vendor-v1"');
headers.set("Cache-Control", "public, max-age=31536000, immutable");
return new Response(response.body, { status: 200, headers });
}
// Route 2: Serve differential update if client possesses dictionary
if (url.pathname.startsWith("/assets/") && clientDictionary) {
// Check if client has vendor-v1 dictionary (hash validation)
const expectedHash = ":dcb-hash-vendor-v1:";
if (clientDictionary.includes(expectedHash)) {
// Fetch pre-computed differential delta from KV or object storage
const deltaResponse = await fetch(`https://storage.codebumble.com/deltas${url.pathname}.dcb`);
if (deltaResponse.status === 200) {
const headers = new Headers(deltaResponse.headers);
headers.set("Content-Type", "application/javascript; charset=utf-8");
headers.set("Content-Encoding", "dcb");
headers.set("Vary", "Accept-Encoding, Available-Dictionary");
return new Response(deltaResponse.body, { status: 200, headers });
}
}
}
// Fallback: Standard fetch with normal compression
return fetch(request);
}
};
7. Security Architecture: Cross-Origin Leaks and Content Isolation
Because compression ratio variations can inadvertently leak confidential user information (the classic CRIME and BREACH attack vectors), the HTTP Compression Dictionary specification enforces rigorous security boundaries:
- Same-Origin Policy: Dictionaries and target resources must adhere strictly to same-origin restrictions unless explicit Cross-Origin Resource Sharing (CORS) headers and cryptographic hash verification are established.
- Path and Context Scoping: The
matchdirective prevents a dictionary containing sensitive user data from being leveraged to compress public scripts. - Cookie and Authentication Cleansing: Dictionaries must never contain session tokens, dynamic CSRF keys, or user-specific PII. Production servers must strip
Set-Cookieheaders from all responses carryingUse-As-Dictionary.
8. Architectural FAQ: Common Questions on Compression Dictionaries
Q1: What happens if a browser does not support Compression Dictionaries?
The protocol is completely backwards-compatible. Clients that do not support compression dictionaries omit the dcb and dcz tokens from their Accept-Encoding header and do not send Available-Dictionary. Servers and edge CDNs detect this and automatically fall back to standard Brotli (br), Zstandard (zstd), or Gzip (gzip).
Q2: Can dynamic JSON API responses use compression dictionaries?
Yes. In fact, dynamic APIs represent one of the highest-value use cases. A web application can designate its static JSON API schema or a daily base dataset as a dictionary. Subsequent polling requests or pagination queries transfer only the modified records, cutting API payload egress by 80% to 90%.
Q3: How does the browser manage dictionary cache storage?
Browsers store compression dictionaries in a dedicated partition of the HTTP disk cache. Dictionaries are subject to standard cache eviction policies (LRU) and Cache-Control max-age limits. If disk pressure forces dictionary eviction, the browser simply stops advertising the dictionary on subsequent requests.
Q4: Does dictionary compression increase server CPU load?
If deltas are generated on-the-fly during peak traffic, real-time compression can increase origin CPU consumption. In enterprise deployments, best practice is to pre-compute differential deltas during the CI/CD build and deployment pipeline, uploading pre-compressed .dcb artifacts directly to edge object storage.
Q5: Which browsers currently support HTTP Compression Dictionaries?
Compression Dictionaries are supported natively in Chromium-based browsers (Google Chrome, Microsoft Edge, Brave, Opera) starting with Chrome 125+. Safari and Firefox have active tracking standards implementations underway in WebKit and Gecko.