Skip to content

How to Enable Brotli in nginx

Key idea:

Brotli (brotli.org, Google) is a compression algorithm 15-25% better than gzip for text (HTML/CSS/JS). Client support 95%+ by 2026. Install in nginx: compile ngx_brotli module (not in the default dynamic pool) or use the nginx-extras package. Add 3 directives + server reload.

Below: step-by-step, working examples, common pitfalls, FAQ.

Step-by-Step Setup

  1. Install ngx_brotli via pre-built package: apt install nginx-module-brotli (Ubuntu 22.04+)
  2. Or compile: git clone --recursive https://github.com/google/ngx_brotli + configure nginx with --add-module
  3. In nginx.conf (http context): load_module modules/ngx_http_brotli_filter_module.so; load_module modules/ngx_http_brotli_static_module.so;
  4. In server block: brotli on; brotli_comp_level 6; brotli_types text/plain text/css application/json application/javascript;
  5. Static files (pre-compressed .br): brotli_static on;
  6. nginx -t && systemctl reload nginx
  7. Verify: curl -H "Accept-Encoding: br" -I https://example.com | grep -i "content-encoding" — should be "br"

Working Examples

ScenarioConfig
nginx.conf modulesload_module modules/ngx_http_brotli_filter_module.so; load_module modules/ngx_http_brotli_static_module.so;
server blockbrotli on; brotli_comp_level 6; brotli_static on; brotli_types text/plain text/css application/json application/javascript application/xml+rss text/xml image/svg+xml;
Pre-compress filesfind /var/www -type f \( -name "*.css" -o -name "*.js" \) | xargs -I{} brotli -q 11 "{}"
ApacheLoadModule brotli_module modules/mod_brotli.so\nBrotliCompressionQuality 5

Common Pitfalls

  • brotli_types missing required MIME — nothing compressed
  • compression level 11 (max) in line — CPU 100%. For realtime 4-6 is optimal
  • brotli_static on without pre-compressed files — no change
  • No gzip fallback — old clients (<5%) without Brotli get uncompressed
  • Proxy-cached responses with gzip — Brotli won't apply to already-gzipped
PerformanceOverall speed score 0-100
Core Web VitalsLCP, FID, CLS — Google metrics
Page SizeSize of HTML, CSS, JS, images
RecommendationsSpecific tips for improvement

Why teams trust us

Lighthouse
analysis engine
CWV
Core Web Vitals
4
Lighthouse categories
Precise
recommendations

How it works

1

Enter page URL

2

Lighthouse analyzes

3

Get CWV scores & tips

Why Does Site Speed Matter?

Page load speed directly impacts conversion, SEO rankings, and user satisfaction. Google uses Core Web Vitals as a ranking factor. Every extra second of load time cancost up to 7% in conversions.

Lighthouse Analysis

Google Lighthouse-based analysis: Performance, Accessibility, Best Practices, SEO.

Core Web Vitals

LCP (rendering), FID (interactivity), CLS (visual stability) — key Google metrics.

Resource Analysis

Breakdown by type: HTML, CSS, JavaScript, images, fonts. Size, request count, blocking resources.

Actionable Advice

Specific recommendations with savings estimates: image compression, caching, minification, etc.

Mobile vs Desktop

Mobile
  • Tested on Moto G Power emulation (slow CPU)
  • Network: 4G (1.6 Mbps, 150ms RTT)
  • Stricter speed scoring
  • Google indexes mobile-first
  • Priority for SEO optimization
Desktop
  • High CPU performance
  • Fast connection without throttling
  • Scores typically 20-40 points higher
  • Important for B2B and corporate sites
  • Use for baseline comparisons

Who uses this

SEO

Core Web Vitals for rankings

Developers

performance optimization

Marketers

speed = conversions

DevOps

performance regression

Common Mistakes

Unoptimized imagesImages can be up to 70% of page weight. Use WebP/AVIF and lazy loading.
Render-blocking JS in &lt;head&gt;Scripts without async/defer block rendering. Move to end or add attribute.
No static asset cachingWithout Cache-Control, the browser reloads CSS/JS on every visit.
Too many HTTP requestsEach request adds latency. Bundle files, use sprites, or inline critical CSS.
Missing compression (gzip/brotli)Compression reduces text resource size by 60-80%. Enable brotli on the server.

Best Practices

Optimize imagesWebP for photos, SVG for icons. loading="lazy" for images below the fold.
Enable brotli compressionBrotli is 15-20% more efficient than gzip. Configure in nginx: brotli on;
Set up cachingStatic: Cache-Control: max-age=31536000, immutable. HTML: max-age=0, s-maxage=60.
Preload critical resources<link rel="preload"> for fonts and CSS. Reduces LCP by 200-500ms.
Test regularlySpeed degrades over time. Check after each deploy and monthly.

Get more with a free account

Speed check history, competitor comparison and PageSpeed monitoring.

Sign up free

Learn more

Frequently Asked Questions

How much better is Brotli than gzip?

For text (HTML/CSS/JS): 15-25% smaller at the same CPU. For binaries (already compressed) — minimal.

Does Brotli work over HTTPS?

Yes; clients don't send Accept-Encoding: br over plain HTTP. Modern sites are all HTTPS.

Client compatibility?

Chrome 50+, Firefox 44+, Safari 11+ (2017). IE no support. By 2026 coverage is 95%+.

How do I verify it works?

<a href="/en/speed">Enterno Speed checker</a> shows response headers. Or DevTools → Network → Response Headers → Content-Encoding.