Gzip vs. Brotli Compression
Gzip and Brotli are both compression algorithms that shrink text-based web files, such as HTML, CSS and JavaScript, before sending them over the network. Brotli generally compresses smaller than Gzip, especially at its higher settings, while Gzip is faster to compress on the fly and is supported by effectively every browser and server in use today. Most modern hosts and CDNs support both and pick the best one automatically.
What compression does for a website
Before sending a file, the server can compress it into a smaller size, and the browser decompresses it automatically on arrival. This mainly helps text-based files such as HTML, CSS, JavaScript, JSON and SVG, which compress very well because of their repetitive patterns. Already-compressed formats like JPEG, PNG, MP4 and WOFF2 fonts gain little or nothing from additional compression and are usually left alone.
Gzip vs. Brotli at a glance
| Gzip | Brotli | |
|---|---|---|
| Introduced | 1992 | 2015, by Google |
| Typical compression ratio | Good | Usually better, especially for text at higher settings |
| Compression speed | Fast | Slower at high settings, similar at low settings |
| Browser support | Universal, including very old browsers | Supported by all current major browsers over HTTPS |
| Best use | Dynamic content compressed on every request | Static files pre-compressed once and reused many times |
Static vs. dynamic compression
For dynamic content generated fresh on each request, such as an HTML page assembled by PHP, the server has to compress it in real time, so compression speed matters. Gzip at a moderate level is a common default for this because it is fast enough not to add noticeable delay. For static files like a site's main CSS or JavaScript bundle, the file can be compressed once in advance at Brotli's highest quality setting and then served instantly to every visitor from that pre-compressed copy, getting Brotli's better ratio without paying its compression time cost on every request.
Enabling compression
Most modern web servers and CDNs support both and negotiate automatically: the browser sends an Accept-Encoding header listing what it supports, and the server responds with whichever it has available, indicated by a Content-Encoding header. Example Nginx configuration:
gzip on;
gzip_types text/css application/javascript text/html;
brotli on;
brotli_types text/css application/javascript text/html;
Apache uses mod_deflate for Gzip and mod_brotli for Brotli, both enabled through the server configuration or, on shared hosting, often already turned on by the host.
Checking which one a site is using
Open a browser's developer tools, go to the Network tab, reload the page, and check a file's response headers for Content-Encoding: gzip or Content-Encoding: br (Brotli's short code). From a terminal:
curl -H "Accept-Encoding: br" -I https://example.com/style.css
If neither header appears, compression may not be enabled at all, which is worth fixing since it is one of the simplest performance wins available on most hosting setups.
Frequently asked questions
Is Brotli always better than Gzip?
Brotli usually compresses text-based files smaller than Gzip, particularly at higher quality settings, but it can be slower to compress on the fly. For pre-compressed static files the difference is pure benefit; for content compressed fresh on every request, Gzip's speed can make it the more practical choice.
Do all browsers support Brotli?
All current major browsers support Brotli over HTTPS connections. Very old or uncommon clients may not, which is why servers check the Accept-Encoding header and fall back to Gzip automatically when Brotli is not supported.
Does compressing images with Gzip or Brotli help?
Not usually. Formats like JPEG, PNG and WebP are already compressed internally, so running Gzip or Brotli on them again saves little or nothing and can occasionally make the file slightly larger. These algorithms are most useful on text-based files.
How do I know if my site is using compression at all?
Check the response headers for a file in your browser's developer tools network tab, looking for Content-Encoding set to gzip or br. If it is missing entirely, compression likely is not enabled on the server.
Does a CDN handle compression for me?
Many CDNs compress files automatically before delivering them, often choosing Brotli or Gzip based on what the visitor's browser supports, without any extra configuration needed on your origin server.
Can I use both Gzip and Brotli on the same site?
Yes, and this is the common setup. The server offers both, and the browser's Accept-Encoding header decides which one is actually used for each visitor, so older clients still get Gzip while modern browsers get Brotli's better compression.
Related topics
- What Is an SSL Certificate? Security & SSL
- What Is a Web Server? Web Servers
- What Is Nginx? Web Servers
- What Is Apache (Apache HTTP Server)? Web Servers
- What Is Shared Hosting? Hosting Basics