Introduction
Brotli is a compression algorithm specified in RFC 7932 and developed by Google. It replaced gzip as the default Content-Encoding for HTTPS traffic in most modern browsers, offering 15-25% better compression ratios for web assets. If you need to compress or decompress Brotli data in the browser, this tool uses the brotli-wasm package for WASM-accelerated processing. No data leaves your browser.
What this tool does
- Compresses text into Brotli format (RFC 7932)
- Decompresses Brotli streams back to the original text
- Outputs compressed data in both hex and base64 formats
- Shows compression ratio percentage for quick comparison
- Accepts hex or base64 input when decompressing (auto-detected)
- Uses WebAssembly for near-native compression speed
How this tool works
The tool dynamically imports the brotli-wasm module on page load, which loads a WebAssembly binary compiled from the reference C implementation. In compress mode, it encodes input text as UTF-8 bytes and passes them to the Brotli compressor. Output is displayed as hex, base64, and a compression ratio percentage. In decompress mode, it auto-detects hex vs base64 input, converts to a Uint8Array, and passes it to the Brotli decompressor. The WASM module loads asynchronously, so the first compression may take a moment while the module initializes. All subsequent operations are fast since the WASM binary is cached in memory.
How Brotli compression works
Brotli improves on DEFLATE by using a larger sliding window (up to 16 MB vs DEFLATE's 32 KB), a built-in static dictionary of 120 KB containing common web text patterns, and second-order context modeling for Huffman coding. The static dictionary includes common HTML, CSS, and JavaScript tokens, which is why Brotli excels at compressing web assets. The algorithm was introduced by Jyrki Alakuijala and Zoltan Szabadka in 2015. All major browsers (Chrome, Firefox, Edge, Safari) support Brotli for Content-Encoding since 2016-2017. The brotli-wasm package compiles the reference C implementation from Google to WebAssembly, providing the same compression quality as server-side Brotli.
How to use this tool
- Select mode: Compress or Decompress.
- For compression: type or paste text. Output shows hex, base64, and compression ratio.
- For decompression: paste hex or base64 Brotli data. The tool auto-detects the format.
- Use the Swap button to switch between modes.
- Wait for the WASM module to load on first use (usually under 1 second).
Real-world examples
Compressing HTML for Content-Encoding comparison
A 10 KB HTML file compresses to approximately 2.5 KB with Brotli level 11, compared to 3.1 KB with gzip level 9. That 20% difference matters for mobile users on slow connections. Compress your HTML here and compare the output size to the DEFLATE tool.
Decompressing a Brotli-encoded API response
If an API returns Content-Encoding: br and you need to inspect the raw response body, extract the compressed bytes as hex or base64 and paste them into the decompress mode. The tool returns the original JSON or HTML payload.
Pre-compressing static assets
CDNs like Cloudflare and Netlify support pre-compressed Brotli files (.br extension). You can compress your JavaScript or CSS text here, save the base64 output, and decode it to a .br file for upload. This avoids on-the-fly compression on the server.
Comparison with similar methods
| Method | Complexity | Typical use |
|---|---|---|
| Brotli (RFC 7932) | LZ77 + context modeling + dictionary | HTTPS Content-Encoding |
| DEFLATE (RFC 1951) | LZ77 + Huffman | gzip, zlib, PNG |
| Zstandard (RFC 8478) | LZ77 + FSE | High-speed compression |
| LZMA | LZ77 + range coding | 7z, xz archives |
Limitations or considerations
Brotli compression in the browser uses the brotli-wasm package, which loads a WASM binary (~200 KB). The first use requires downloading and compiling this module. Brotli is designed for text compression and includes a static dictionary optimized for web content; binary data like images will not compress well. The tool uses a default quality level; server-side Brotli allows tuning quality levels 0-11, where 11 gives the best ratio but is 50x slower than level 4.
Frequently asked questions
Why is Brotli better than gzip for web content?
Brotli uses a larger window (16 MB vs 32 KB), a built-in 120 KB static dictionary of common web tokens, and second-order context modeling. For HTML, CSS, and JavaScript, Brotli typically achieves 15-25% smaller output than gzip at the same quality level.
Can I use Brotli over HTTP (non-HTTPS)?
Browsers only send Accept-Encoding: br over HTTPS. This is a browser policy, not a Brotli limitation. The algorithm itself works over any transport, but for web delivery you need TLS.
What compression level does this tool use?
The brotli-wasm package uses a default quality level. The reference C library supports levels 0-11, where 11 gives maximum compression but takes significantly longer. This tool uses the default, which balances speed and ratio.
Is Brotli supported in all browsers?
Brotli has been supported in Chrome 50+, Firefox 44+, Edge 15+, and Safari 11+. It is not supported in IE11 or older browsers. For maximum compatibility, serve both Brotli and gzip with content negotiation.
Conclusion
Brotli is the modern standard for web content compression, outperforming gzip by 15-25% on text assets. This tool provides browser-based compression and decompression using a WASM-compiled implementation. Use it to compare compression ratios, inspect Brotli-encoded responses, or pre-compress static assets for CDN delivery.