Gzip and Brotli
Gzip and Brotli are compression algorithms for text assets such as HTML, CSS, JavaScript, JSON, and SVG. The server compresses, the browser decompresses, and the transfer gets smaller and faster.
The short difference
| Aspect | Gzip | Brotli |
|---|---|---|
| Support | Almost every browser | Modern browsers |
| Ratio | Good | Usually 15–25% smaller for text |
| Compression speed | Fast | Slightly slower |
| When to use | Universal fallback | Priority for static assets |
How to enable it
- LiteSpeed/cPanel: usually on by default; check the
Content-Encodingresponse header. - Nginx: enable
gzip on;and the Brotli module if available. - CDN: many CDNs compress automatically at the edge.
- WordPress: a cache plugin usually handles HTML and static assets.
Test with `curl -I -H "Accept
- Encoding: br,gzip" https://example.com` and look at the
Content-Encodingheader.
What to watch for
- Do not compress images/video. Those formats are already compressed; the result can be larger.
- Avoid double compression. If the CDN already compresses, the origin does not need to do it again.
- Watch
Content-Length. Compression changes the size; do not cache the wrong header. - Brotli needs HTTPS in many setups. Make sure the connection is secure.
- Compression costs CPU. On a small server, measure the impact before raising the compression level.
Already-compressed files such as JPEG, PNG, WebP, MP4, and ZIP should not be compressed again. Compression helps large JSON API responses; for very small responses, header overhead can outweigh the saving. Measure with DevTools or curl before changing the configuration.
FAQ
Is Brotli always better than Gzip?
Brotli usually gives a smaller ratio, but Gzip is more universal and faster to compress. Offer both and let the browser choose.
Does compression slow the server?
It costs CPU, but that is usually much smaller than the bandwidth and transfer-time savings.
How do I confirm compression is active?
Look for `Content
- Encoding: br
orgzip` on HTML/CSS/JS responses. If it is missing, check the server or CDN configuration.
Disclaimer: Hosting Wiki articles are prepared for educational and reference purposes. Hosting technology keeps evolving, so some technical details may change over time.