--- title: Gzip and Brotli description: "Text compression for HTML, CSS, and JS. Brotli gives a smaller ratio; gzip is more universal." canonical: https://penasihathosting.com/en/hosting-wiki/gzip-brotli type: wiki locale: en updated: 2026-10-29 author: Willya Randika --- # Gzip and Brotli ## Overview - **Summary:** Text compression for HTML, CSS, and JS. Brotli gives a smaller ratio; gzip is more universal. - **Author:** Willya Randika ([profile](/penulis/willya-randika)) ## Article **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-Encoding` response 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-Encoding` header. ## 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 Brotli usually gives a smaller ratio, but Gzip is more universal and faster to compress. Offer both and let the browser choose. It costs CPU, but that is usually much smaller than the bandwidth and transfer-time savings. Look for `Content-Encoding: br` or `gzip` on HTML/CSS/JS responses. If it is missing, check the server or CDN configuration.