Brotli vs Gzip
What Brotli and Gzip Each Do Best
Brotli vs gzip is a comparison of two HTTP compression methods for text-based web files. Brotli is the newer method and usually produces smaller text files than gzip, while gzip is older, generally quicker to compress at high settings and supported everywhere. Both work the same way from the browser's point of view: the server sends a compressed body with a Content-Encoding header.
Brotli also includes a built-in dictionary of words, phrases and code patterns common on the web. This helps it handle small text files such as HTML and CSS, where gzip has less to draw on. Gzip relies only on repetition inside the file it compresses. If you need the basics first, read the gzip compression article.
Compression Ratio, CPU Cost and Speed
The compression ratio is the main reason to choose Brotli. At comparable effort, Brotli typically gives smaller text files, and smaller files mean less data to transfer. That matters most on slow mobile networks and for pages with many scripts and stylesheets.
The trade-off is processor time. Compressing a response takes CPU work, and the highest Brotli settings are slow. Gzip compresses quickly, which makes it practical for responses generated on every request. Decompression is fast for both methods, so visitors rarely notice a difference on the receiving side.
The right setting therefore depends on whether a file is compressed once or on every request. The next section explains that difference.
Static Files Versus On-the-Fly Compression
Compression happens in two ways. Static compression means a file is compressed once, ahead of time, and the compressed copy is stored next to the original. On-the-fly (dynamic) compression means the server compresses each response when it is requested, which is common for pages generated by PHP or a database.
For static files such as a site's stylesheets and scripts, Brotli suits the job well, because it can be compressed at its highest setting once, without slowing down any visitor. For dynamic responses, a moderate Brotli setting or gzip often gives a better balance, since the server does the work under real traffic. Minifying files with minification before either method is applied still reduces the input size.
Choosing Between Them on a Content Site
A developer runs a content site where the stylesheets and scripts are built in advance, and the article pages are generated by PHP on each request. The static assets are compressed with Brotli at build time, so each visitor receives smaller files at no extra cost per request. The article pages use gzip, which keeps the server's CPU load predictable when traffic rises.
A different site, with almost no dynamic pages, might use Brotli for nearly everything. The right choice depends on traffic, the server's CPU capacity and the kind of content being served.
Frequently asked questions
Do All Browsers Support Brotli?
Major modern browsers support Brotli, and it is generally used over secure HTTPS connections. Some older clients do not support it. Servers that offer both methods check the Accept-Encoding header and fall back to gzip when Brotli is not listed, so no visitor is left without compression.
Should I Switch From Gzip to Brotli?
Switching is worthwhile for many text-heavy sites, especially when files can be compressed in advance. It is not urgent for every site, and keeping gzip as a fallback is normal. Measure the transferred size and server load before and after a change, and compare the results against your own traffic.