Brotli
By Google
Brotli is a general-purpose lossless compression algorithm and data format developed by Google, combining a variant of the LZ77 algorithm with Huffman coding and a large predefined dictionary of common web strings. It was designed…
Definition
Brotli is a general-purpose lossless compression algorithm and data format developed by Google, combining a variant of the LZ77 algorithm with Huffman coding and a large predefined dictionary of common web strings. It was designed primarily to shrink web content such as HTML, CSS, and JavaScript more effectively than older algorithms like gzip, and it is now widely supported as a content-encoding option in modern web browsers and servers.
Overview
Brotli was created to address a specific bottleneck in web performance: gzip, the long-standing standard for HTTP content compression, was reaching diminishing returns as web assets grew larger and more repetitive across sites, and a newer algorithm with a bigger compression window and web-aware dictionary could shrink the same content further without unacceptable performance cost. Google designed Brotli specifically with static web content (HTML, CSS, JavaScript, fonts) in mind, rather than as a purely general-purpose replacement for older formats. Brotli's compression pipeline combines a modernized LZ77-style algorithm, which finds and references repeated byte sequences, with context-modeled Huffman coding for entropy coding, similar in spirit to gzip's DEFLATE but with a larger sliding window (up to 16 MB versus DEFLATE's 32 KB) that lets it find repeated patterns much further back in a file. Brotli also ships with a static dictionary of roughly 120,000 common words and phrases drawn from web content, letting it reference frequent strings, HTML tags, common JavaScript keywords, and the like without having to encode them from the input data at all. Compared to gzip, Brotli generally achieves meaningfully smaller output for the same input, particularly for text-heavy web assets, at the cost of typically slower compression (though decompression speed is comparable or faster). Compared to newer general-purpose compressors like Zstandard, which prioritizes very fast compression and decompression speed with tunable ratio, Brotli at its higher quality settings tends to produce smaller output for web-style text, while Zstandard often wins on raw throughput for general-purpose or streaming use cases. In practice, Brotli is used as an HTTP content-encoding, negotiated automatically between browsers and servers via the `Accept-Encoding` and `Content-Encoding` headers, so that compatible clients receive Brotli-compressed HTML, CSS, and JavaScript with no visible change to the site itself. It is also used in some font formats (WOFF2 uses Brotli internally) and as a general compression library outside the browser context. Brotli's slower compression speed at its highest quality settings makes it less suited to scenarios needing fast, real-time compression of arbitrary or already-compressed data, and its static dictionary's web-content bias means it offers less advantage on non-textual or non-web data such as binary blobs or already-compressed media. Servers commonly pre-compress static assets with Brotli at build time to absorb the compression cost once, then serve the pre-compressed files repeatedly, rather than compressing on the fly for every request. Command-line tools and language bindings for Brotli are now widely available, letting developers integrate it into build pipelines, CDNs, or custom asset-serving code with the same ease as calling a gzip library.
Key Concepts
- Combines LZ77-style matching with context-modeled Huffman coding
- Larger sliding window than DEFLATE finds longer-range repeated patterns
- Ships a static dictionary of common web strings and phrases
- Generally compresses text-heavy web content smaller than gzip
- Widely supported as an HTTP content-encoding in modern browsers
- Used internally within the WOFF2 web font format
- Multiple quality levels trade compression speed against ratio
- Decompression speed comparable to or faster than gzip