What Is Brotli? β Definition and How It Works
Learn what Brotli compression is, how its built-in dictionary beats gzip on HTML, and what it means for HTTP clients.
Brotli is a compression algorithm designed for the web, advertised as br in HTTP content encoding. It compresses text noticeably smaller than gzip, largely because it ships with a dictionary of common web strings.
1. Why It Beats Gzip on Web Content
Brotli includes a static dictionary of roughly 13,000 common strings β HTML tags, CSS properties, JavaScript keywords, frequent English words. Sequences already in the dictionary are referenced rather than described.
Since HTML is dominated by exactly those strings, the gain on web text is substantial: single-digit to low-double-digit percentage improvements over gzip at comparable settings are typical, without any change in decompression cost that a client would notice.
2. In HTTP
Accept-Encoding: br, gzip, deflate
Content-Encoding: br
The negotiation is ordinary content negotiation. A server that supports Brotli and sees it offered will generally prefer it.
3. What This Means for a Client
Almost nothing, if the HTTP library handles it β and the failure mode when it does not is distinctive.
import requests
r = requests.get(url, headers={"Accept-Encoding": "br, gzip"})
print(r.headers.get("content-encoding"), len(r.content))
requests needs brotli or brotlicffi installed to decode br. Without it, advertising br and receiving it yields binary garbage, not an error β a body that parses as HTML with no matches, which reads as "the site changed its layout".
The rule follows: only advertise an encoding you can actually decode.
4. Fingerprinting Relevance
The Accept-Encoding value is part of a request's header signature. Browsers send a specific set in a specific order; a client that omits br while claiming to be a current browser is inconsistent in a way that is trivially checked.
This is one of the cheapest header mismatches to get right, and one of the more common to get wrong.
5. Compression Levels
Brotli's quality range is 0β11, considerably wider than gzip's 1β9.
- Low levels are fast, suitable for dynamic responses compressed per request.
- High levels are slow to compress but decompress just as quickly, which makes them ideal for static assets compressed once at build time.
Level 11 on a dynamic response is a common misconfiguration: it can cost more server time than the bytes saved are worth.
6. Where It Is Not Used
Over plain HTTP β most browsers only offer br over HTTPS.
For already-compressed data β images, video, and archives gain nothing.
In non-HTTP contexts β gzip remains the default for files, pipelines, and archives, where compatibility matters more than ratio.
7. Storing Collected Data
For archived HTML, Brotli at a high level is an excellent choice: HTML compresses extremely well, storage is the dominant cost of an archive, and decompression stays fast.
The trade against gzip is ecosystem support in downstream tooling rather than any performance concern β which is why gzip persists where files pass between many tools.
8. Summary
Brotli is a web-oriented compression algorithm advertised as br, whose built-in dictionary of common web strings makes it meaningfully smaller than gzip on HTML.
Only advertise it if your client can decode it, since the failure is silent binary garbage rather than an error; keep Accept-Encoding consistent with the browser you claim to be; and use high quality levels only for content compressed once, not per request.