Skip to main content

Performance

Gzip and Brotli: Compressing Text for Faster Downloads

Shrink HTML, CSS and JavaScript before they cross the wire.

Quick answer

Gzip and Brotli are compression algorithms that shrink text-based files (HTML, CSS, JavaScript, JSON) before sending them over the network. Brotli typically achieves 15–25% better compression than Gzip. Both are enabled at the server or CDN level and can cut transfer size dramatically.

Text assets compress well because HTML and code repeat the same patterns. Enabling Brotli (with Gzip fallback for older clients) reduces bytes transferred, speeds up page loads and improves TTFB-to-interactive time — usually with a single server or CDN setting.

Check your website

See how your site handles gzip and brotli: compressing text for faster downloads — free, no account needed.

For business owners

Compression is one of the easiest performance wins: flip a setting, instantly send less data on every page view. For text-heavy pages or large JavaScript bundles the savings are substantial, which means faster loads, happier visitors and better PageSpeed scores — with no visible change to your site.

How it works (technical)

The server compresses the response body and sets Content-Encoding: br (Brotli) or gzip. Browsers advertise supported encodings in Accept-Encoding. Enable Brotli and Gzip for text/html, text/css, application/javascript, application/json and fonts. Do not compress already-compressed formats (JPEG, PNG, WebP, video). Most CDNs compress automatically; on Apache use mod_brotli/mod_deflate, on Nginx gzip on and brotli on. Pre-compress static assets at build time for maximum efficiency.

Real-world example

A documentation site served 800 KB of uncompressed JavaScript. Enabling Brotli at the CDN reduced the transfer to under 200 KB with no code changes, cutting load time on slow connections noticeably and improving PageSpeed scores.

Why it matters

Smaller transfers mean faster loads, especially on mobile networks. PageSpeed and performance scanners routinely flag missing text compression.

How to fix it

  1. Enable Brotli and Gzip on your web server or CDN.

  2. Ensure text MIME types (HTML, CSS, JS, JSON, SVG) are compressed.

  3. Verify with curl: curl -H "Accept-Encoding: br" -I https://yoursite.com.

  4. Pre-compress static assets at build time if your stack supports it.

  5. Do not double-compress images or other binary formats.

Best practices

  • Prefer Brotli with Gzip as fallback for older clients.

  • Compress at the CDN edge so origin load stays low.

  • Combine compression with caching for maximum repeat-visit speed.

Common mistakes

  • Leaving compression disabled on the origin when the CDN is not in front of everything.

  • Compressing images (wastes CPU, no meaningful size gain).

  • Only enabling Gzip when Brotli is available and better.

Frequently asked questions

Does compression slow down the server?

Compression uses CPU, but modern hardware and CDN edge compression handle it easily. The network savings almost always outweigh the cost, especially for large text files.

How do I check if my site uses Brotli?

Inspect a response in DevTools Network tab and look for Content-Encoding: br. Or use PageSpeed Insights, which flags missing compression.

Put this into practice

See how your site scores with Plexa Trust — start with a free scan, then unlock the complete audit on Pro.

Scan your website free

See Pro plans · Create account