Performance & Maintenance

Gzip and Brotli Compression: What They Are and How They Reduce Web Size

Gzip and Brotli are compression algorithms the server applies to text files before sending them to the browser, shrinking their size by 60–90% and speeding up page load.

A laptop displaying an analytics dashboard with real-time data tracking and analysis tools.

Gzip and Brotli are compression algorithms the web server applies to text files (HTML, CSS, JavaScript, JSON) before sending them to the browser, shrinking their size by 60–90% without losing any data. The browser downloads fewer bytes, the page loads faster, and server bandwidth consumption drops.

This article explains how each algorithm works, which one to choose, and how to enable them on the most common server setups.

How text compression works on the web

When a browser requests a page, it sends an HTTP header listing the compression algorithms it supports:

Accept-Encoding: gzip, deflate, br

The server reads that header and, if compression is enabled, responds with the compressed file and signals it:

Content-Encoding: br

The browser decompresses the file in milliseconds and processes it normally. For the user, the whole process is invisible — they just experience a faster-loading page.

Compression only applies to plain-text resources. JPG, WebP, and PNG images already use their own internal compression formats; running Gzip or Brotli on top of them won't reduce their size and may even increase it slightly.

What is Gzip?

Gzip is the oldest and most universal web compression algorithm. It derives from the DEFLATE format and was standardized for HTTP/1.1 in 1999. Today, all modern browsers and servers support it, so enabling it is always safe.

Gzip compression levels

Gzip offers levels 1 through 9. Level 1 compresses less but very quickly; level 9 compresses the most but uses more CPU. For most sites, level 5 or 6 is the optimal balance point.

Level Compression Speed Recommended for
1–2 Low Very fast CPU-constrained servers
5–6 Medium-high Fast Most websites
9 Maximum Slow Pre-compressed static files

What is Brotli?

Brotli is a compression algorithm developed by Google, released in 2015 and standardized for HTTPS in RFC 7932. It uses a pre-trained dictionary with common web vocabulary (typical HTML, CSS, and JS fragments) and an improved LZ77 algorithm.

The result: Brotli compresses 15–25% more than Gzip for web text files, without significantly increasing decompression time in the browser. Its only limitation is that it only works over HTTPS — browsers require this by security policy.

Brotli compatibility

Since 2017, all major browsers (Chrome, Firefox, Safari, Edge) support Brotli. If a visitor's browser doesn't support it, the server must fall back to Gzip automatically — any correct server configuration handles this transparently.

Gzip vs. Brotli: practical comparison

Criteria Gzip Brotli
Year introduced 1996 / HTTP 1999 2015 / HTTPS 2016
Compression ratio (web text) 60–75% 75–90%
Compression speed Fast Slower at high levels
Decompression speed Very fast Similar to Gzip
Requires HTTPS No Yes
Browser support Universal 95%+ (all modern browsers)

Recommended strategy: enable Brotli as the first option and Gzip as the fallback. Visitors with modern browsers get Brotli; the rest get Gzip. Never leave compression disabled.

How to enable Gzip and Brotli on your server

Apache with .htaccess

The simplest method on shared hosting or cPanel is to add these lines to the .htaccess file in your site root:

# Gzip
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json text/xml application/xml text/plain
</IfModule>

# Brotli (if the module is available)
<IfModule mod_brotli.c>
  AddOutputFilterByType BROTLI_COMPRESS text/html text/css application/javascript application/json text/xml application/xml text/plain
</IfModule>

If your hosting provider doesn't have mod_brotli, the Gzip configuration will still work without any issues.

Nginx

# Gzip
gzip on;
gzip_comp_level 6;
gzip_types text/plain text/css application/javascript application/json text/xml;

# Brotli (requires ngx_brotli module)
brotli on;
brotli_comp_level 6;
brotli_types text/plain text/css application/javascript application/json text/xml;

Cloudflare

If your site goes through Cloudflare, both Gzip and Brotli compression are enabled automatically on the free plan. You don't need to touch the server — Cloudflare compresses files at the edge before delivering them to the visitor.

How to verify compression is active

You can check it several ways:

  • Chrome DevTools → Network → Headers: look for the Content-Encoding: gzip or Content-Encoding: br response header.
  • GTmetrix or PageSpeed Insights: both tools flag uncompressed text files as opportunities.
  • GiftOfSpeed (giftofspeed.com): a free, direct compression test for any URL.

For a full performance audit covering compression, caching, and more, the team at elenlace.com can help you identify and resolve every bottleneck on your site.

Explore more guides in our web performance section to optimize every layer of your stack.

Key takeaways

  • Gzip and Brotli compress text files (HTML, CSS, JS) before sending them to the browser, cutting size by up to 90%.
  • Brotli delivers 15–25% better compression than Gzip, but requires HTTPS.
  • The optimal strategy is to enable Brotli as the first choice and Gzip as the fallback.
  • On Apache, configure it with mod_deflate and mod_brotli via .htaccess.
  • Cloudflare enables compression automatically, even on the free plan.
  • Compression only applies to text files — images already have their own internal compression.

Not sure if your site has compression properly configured? Contact us at elenlace.com and we'll review it for free.

FAQ

Can Gzip or Brotli compression break my site?

No. Compression is transparent to both the browser and the user. If something goes wrong with the configuration, the server simply sends the file uncompressed — never a corrupted file.

How much can compression improve my PageSpeed score?

It depends on the current size of your uncompressed files. On unoptimized sites, enabling Gzip can cut load time by 0.3–1.5 seconds and directly raise the PageSpeed score by several points.

Is Brotli compatible with WordPress?

Yes. WordPress generates standard HTML, CSS, and JS that Brotli compresses without any issues. You only need your server or CDN to have Brotli enabled — WordPress itself needs no additional configuration.

Should I enable compression for images?

No. JPG, WebP, PNG, and AVIF are already internally compressed. Applying Gzip or Brotli on top of them won't reduce their size and may even increase it slightly. Limit HTTP compression to text files only.

Useful resources

Other providers and guides worth comparing:

← All