Introduction
Brotli is a compression method from Google, first used inside WOFF2 web fonts and
published for general use in 2015. The format is RFC 7932. Its main job is compressing
web pages, scripts and style sheets in transit: browsers ask for it with
Accept-Encoding: br, and it usually makes text smaller than
gzip does. A .br file is a
Brotli stream saved to disk, most often a file compressed ahead of time, such as
app.js.br, for a web server to send as it is.
Structure
A Brotli stream has no magic number, file name or checksum, so a .br file
can only be recognised by its extension. It is a stream of bits:
0Stream header the window size, from 1 KB to 16 MB1 to 7 bits…Meta-blocks each a header with its length and a last flag, then the compressed datarepeated
Each meta-block combines LZ77 copies of earlier data with Huffman coding chosen by context, so the code for a byte can depend on the bytes before it. Brotli also has a built-in dictionary of about 120 KB of common words and phrases from web pages and other text, which copies can refer to; this is why it does so well on small text files.
Links
Software
- brotli, the command-line tool (macOS, Linux, Windows)
- Web browsers, which decode Brotli responses from web servers
Developers
Reference
- RFC 7932, Brotli Compressed Data Format