Brotli vs Gzip: Modern Web Compression Methods - Colin Mackay

Comparing Brotli and Gzip for HTTP compression: speed, ratio, browser support, and server configuration.

Last updated: 24 April 2026

HTTP Compression in 2026

HTTP compression reduces the size of text-based resources (HTML, CSS, JavaScript, JSON, SVG) transferred between servers and browsers. The two dominant algorithms are Gzip (the established default since the late 1990s) and Brotli (Google's newer alternative, standardised in 2015). Both are supported by every modern browser.

Gzip: The Established Standard

Gzip uses the Deflate algorithm (a combination of LZ77 and Huffman coding). It has been the web's default compression since HTTP/1.1 formalised the Content-Encoding: gzip header.

Characteristics

  • Universal support — every browser, proxy, and CDN handles Gzip
  • Fast compression at typical server settings (level 6 is the common default)
  • Compression levels 1–9 (higher = smaller output, slower encoding)
  • Mature tooling and near-zero configuration required on all web servers

Brotli: Better Ratios, Modern Design

Brotli was developed by Google and published as RFC 7932 in 2016. It includes a built-in static dictionary of common web content (HTML tags, CSS properties, JavaScript keywords), which gives it a significant advantage over Gzip for typical web resources.

Characteristics

  • 15–25 % smaller output than Gzip at comparable quality settings
  • Compression levels 0–11 (levels 10–11 are very slow and intended for pre-compression)
  • Built-in dictionary tuned for web content delivers outsized gains on HTML, CSS, and JS
  • Supported in all modern browsers (Chrome, Firefox, Safari, Edge) over HTTPS
  • Decompression speed is comparable to Gzip

Performance Comparison

Metric Gzip (level 6) Brotli (level 4) Brotli (level 11)
Compression ratio (typical HTML)~5.5×~6.3×~7.1×
Compression speedFastComparableVery slow
Decompression speedFastFastFast
Browser supportUniversalAll modern (HTTPS)All modern (HTTPS)
CPU cost (server, real-time)LowModerateHigh

The key insight: Brotli at level 4–5 compresses better than Gzip at level 9 while being roughly as fast. Brotli at level 11 produces the smallest files but is impractical for on-the-fly compression.

Server Configuration

Nginx

# Gzip (typically in nginx.conf)
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;
gzip_comp_level 6;

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

Apache

# Gzip
LoadModule deflate_module modules/mod_deflate.so
AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json

# Brotli (Apache 2.4.26+)
LoadModule brotli_module modules/mod_brotli.so
AddOutputFilterByType BROTLI_COMPRESS text/html text/css application/javascript application/json

Cloudflare

Cloudflare automatically applies Brotli compression to eligible responses when the browser sends Accept-Encoding: br. No server-side configuration is needed.

Practical Strategy

Pre-compression (Recommended for Static Sites)

For static sites and build-time assets, pre-compress files at the highest level and serve the pre-compressed versions:

# Pre-compress with Brotli level 11 at build time
find ./dist -type f \( -name "*.html" -o -name "*.css" -o -name "*.js" -o -name "*.json" -o -name "*.svg" \) \
  -exec brotli --best --force {} \;

Configure your web server or CDN to serve .br files when the browser supports Brotli, falling back to Gzip or uncompressed.

Dynamic Compression

For dynamically generated content (API responses, server-rendered HTML), use Brotli at level 4–5 for a good balance of speed and ratio, or Gzip at level 6 if CPU overhead is a concern.

When to Use Which

Use Brotli when:

  • You are serving content over HTTPS (Brotli requires it)
  • You can pre-compress at build time (use level 11)
  • You want the smallest possible transfer sizes
  • Your CDN supports Brotli (most do: Cloudflare, Fastly, AWS CloudFront)

Use Gzip when:

  • You need to support very old clients or proxies
  • You are serving over plain HTTP (some implementations only use Brotli over HTTPS)
  • Server CPU is constrained and you cannot pre-compress
  • As a fallback for clients that do not advertise Brotli support

Frequently Asked Questions

Should I use both Gzip and Brotli?

Yes. Serve Brotli to browsers that support it and fall back to Gzip for those that do not. Most CDNs and web servers handle this negotiation automatically based on the Accept-Encoding header.

Does Brotli work with HTTP/2 and HTTP/3?

Yes. Compression is independent of the HTTP version. Brotli works identically over HTTP/1.1, HTTP/2, and HTTP/3.

Is Zstandard coming to HTTP?

There is ongoing work to add Zstandard as a Content-Encoding option, but browser support remains experimental. For web content, Brotli is the practical choice for the foreseeable future.