Перейти к содержимому
Skip to content
← All articles

Gzip vs Brotli: Web Compression Compared

Why Compression Matters

Every byte transferred over the network costs time. A 500KB JavaScript bundle takes 100ms to download on a 40 Mbps connection — but compressed to 150KB with Brotli, it takes only 30ms. Multiply this across all resources (HTML, CSS, JS, JSON, SVG) and compression can reduce page load time by 50–70%.

Web compression works by finding redundant patterns in text-based files and replacing them with shorter representations. Both Gzip and Brotli are lossless — the original data is perfectly reconstructed on the client side. The browser advertises supported encodings via the Accept-Encoding header, and the server responds with the compressed version.

Gzip: The Established Standard

Gzip has been the default web compression since the mid-1990s. It uses the DEFLATE algorithm (a combination of LZ77 and Huffman coding). Virtually every browser, server, CDN, and proxy supports it.

# Nginx Gzip configuration
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 256;
gzip_types
    text/plain
    text/css
    text/javascript
    application/javascript
    application/json
    application/xml
    image/svg+xml
    application/wasm;

Gzip compression levels range from 1 (fastest, least compression) to 9 (slowest, most compression). Level 6 is the common default — it offers a good balance between compression ratio and CPU cost.

Gzip LevelCompression RatioSpeedUse Case
1~60%Very fastReal-time/dynamic content
4–6~70–75%Good balanceGeneral web serving
9~77%SlowPre-compressed static assets

Brotli: The Modern Alternative

Brotli was developed by Google and released in 2015. It uses a combination of LZ77, Huffman coding, and a pre-defined dictionary of common web content (HTML tags, CSS properties, JavaScript keywords). This dictionary gives Brotli a significant advantage for web content specifically.

# Nginx Brotli configuration (requires ngx_brotli module)
brotli on;
brotli_comp_level 6;
brotli_min_length 256;
brotli_types
    text/plain
    text/css
    text/javascript
    application/javascript
    application/json
    application/xml
    image/svg+xml
    application/wasm;

Brotli levels range from 0 to 11. Levels 0–4 are comparable in speed to Gzip. Levels 5–9 are significantly slower but produce smaller output. Levels 10–11 are extremely slow and only suitable for static pre-compression.

Head-to-Head Comparison

FeatureGzipBrotli
AlgorithmDEFLATE (LZ77 + Huffman)LZ77 + Huffman + static dictionary
Compression ratioGood (baseline)15–25% better than Gzip
Compression speedFast at all levelsFast at 0–4, slow at 10–11
Decompression speedFastComparable to Gzip
Browser support100%97%+ (all modern browsers)
SSL/TLS проверку requiredNoYes (browsers only support over HTTPS)
Server supportBuilt-in everywhereRequires module/plugin
Content-Encodinggzipbr

Real-World Compression Results

Typical compression ratios for common web assets:

File TypeOriginalGzip (level 6)Brotli (level 6)Brotli (level 11)
jQuery 3.7 (min)87 KB30 KB (66%)27 KB (69%)25 KB (71%)
Bootstrap CSS (min)161 KB23 KB (86%)19 KB (88%)17 KB (89%)
React (prod)142 KB46 KB (68%)40 KB (72%)37 KB (74%)
HTML page (avg)50 KB12 KB (76%)10 KB (80%)9 KB (82%)
JSON API документацию response100 KB15 KB (85%)12 KB (88%)11 KB (89%)

Static Pre-Compression

For static assets (CSS, JS, SVG), pre-compress files at build time with maximum compression. The server serves the pre-compressed file directly without compressing on each request:

# Pre-compress at build time
gzip -9 -k dist/app.js        # Creates app.js.gz
brotli -q 11 dist/app.js      # Creates app.js.br

# Nginx serves pre-compressed files automatically
gzip_static on;    # Serve .gz files if they exist
brotli_static on;  # Serve .br files if they exist

This gives you the best of both worlds: maximum compression ratio (level 11 Brotli) without any CPU cost at serving time. Build pipelines should generate both .gz and .br versions of every static asset.

What NOT to Compress

Compression is counterproductive for:

Configuration Best Practices

Verifying Compression

# Check compression with curl
curl -I -H "Accept-Encoding: br,gzip" https://example.com/
# Look for: Content-Encoding: br (or gzip)

# Check compressed size
curl -s -o /dev/null -w "%{size_download}" \
    -H "Accept-Encoding: br" https://example.com/assets/app.js

# Use Enterno.io HTTP headers checker to verify
# Content-Encoding header on any URL

Conclusion

Brotli is the superior choice for web compression — it produces 15–25% smaller files than Gzip for typical web content, with comparable decompression speed. Use Brotli as your primary encoding with Gzip as fallback. Pre-compress static assets at maximum level, use moderate levels for dynamic content, and always verify compression is active via response headers. This single optimization can reduce bandwidth costs and improve page load times significantly.

Check your website right now

Check now →
More articles: Performance
Performance
Web Application Caching Strategies
14.03.2026 · 10 views
Performance
Website Speed Optimization: A Complete Guide
11.03.2026 · 13 views
Performance
CDN Cache Invalidation: Strategies for Delivering Fresh Content
16.03.2026 · 18 views
Performance
Resource Hints Explained: Prefetch, Preload, Preconnect, DNS-Prefetch
16.03.2026 · 13 views