Glossary / gzip / Brotli
What is gzip and Brotli compression
gzip and Brotli are compression methods a web server uses to shrink text files (HTML, CSS, JS) before sending them to the browser, which unpacks them on the fly. Pages then transfer noticeably less data and load faster.
Check your site
With each request the browser lists the compression methods it supports in the Accept-Encoding header. The server compresses the response and marks it with Content-Encoding: gzip or br. Text files compress very well, often becoming 3 to 4 times smaller.
gzip is old and supported everywhere. Brotli, from Google, is newer and usually compresses tighter, especially at higher levels. Modern servers often support both: the browser lists the methods it accepts, and the server sends Brotli when the browser supports it.
Compression is worth it only for text. Images, video and archives are already compressed, so gzip and Brotli are not applied to them: it would only waste server effort.
Example
content-encoding: br
Common mistakes
- Thinking compression lowers quality. It is lossless, and the file unpacks exactly as it was.
- Compressing images and video again. They are already compressed, so nothing is gained and CPU time is wasted.
- Assuming Brotli is always better. When dynamic content is compressed on the fly, a high Brotli level can be slower than gzip.
- Forgetting to enable compression on the server and serving pages at full size.