OOmnistu

Blog / Performance

Performance

Brotli vs gzip: which compression should your site use

gzip (RFC 1952, 1996) is the widely supported baseline HTTP clients negotiate from; Brotli (RFC 7932, 2016) packs text tighter but charges CPU for it at high quality levels. How Accept-Encoding negotiation, Vary, precompression, browser support and CDN defaults shape the choice - from both projects' specs and server docs, read 21 November 2026.

OOmnistu
Reviewed 2026-11-21 · 5 min read

gzip was standardized in May 1996 as RFC 1952. Brotli arrived in 2016 (RFC 7932, July 2016) and, per Google's own README, is "similar in speed with deflate but offers more dense compression". Neither is going anywhere: gzip is the baseline the negotiation falls back to, and Brotli is the denser option most browsers now accept. The decision is not which format is "better" in the abstract; it is what to enable on your server or CDN, at what level, and what to precompress. This article compares the two from the specs and the server/CDN documentation, all read 21 November 2026, and names no default winner.

How the negotiation actually works

Per MDN's HTTP reference: the browser sends an Accept-Encoding header listing what it can decode (for example gzip, deflate, br, zstd, optionally with q-value weights); the server picks one and answers with a Content-Encoding header naming what it used - br for Brotli (RFC 7932), gzip for the LZ77+CRC32 format, zstd for Zstandard (RFC 8878). If nothing matches, identity - uncompressed - is a valid outcome, so no client is ever forced to decode something. One operational consequence: because the same URL now has different bytes per client, MDN's Vary documentation says caches need Vary: Accept-Encoding so the compressed and uncompressed variants are cached separately rather than served crosswise.

What each format is

gzip is LZ77 with a 32-bit CRC, the format of the original UNIX gzip program, and it is the widely supported baseline: old browsers, API clients, proxies and monitoring tools already speak it. Brotli is a newer LZ77 variant with Huffman coding and 2nd-order context modeling (per the google/brotli README, MIT-licensed), designed for denser output at comparable decode speed. Two README caveats worth knowing: Brotli is a stream format with no checksums or stored uncompressed length, and its encoding cost is a dial, not a constant.

Levels are where the cost lives

Brotli's encoder takes a quality parameter from 0 to 11; the reference library's default is 11, but that is a library default, not deployment advice. Quality 11 is heavy for on-the-fly encoding - it shines as a build-time step, where you compress static assets once and serve the .br files. On the server side, defaults differ by software, not by spec: nginx's gzip module defaults to gzip_comp_level 1 (range 1-9) with gzip off entirely by default, while the ngx_brotli module defaults to brotli_comp_level 6. The practical split: precompressed static assets can afford Brotli 11; dynamic responses want gzip or a mid-range Brotli level so encoding CPU stays cheaper than the bytes saved.

What servers and CDNs do today

nginx ships gzip in core but not Brotli: Brotli on nginx means building or installing Google's ngx_brotli, which is two modules - a filter for on-the-fly compression and a static module for serving pre-compressed files. CDNs decide much of this for you: Cloudflare's content-compression documentation says it serves Gzip, Brotli and Zstandard to browsers that support them for a list of text content types, with Zstandard enabled through Compression Rules. One browser-side restriction to plan around: Chromium's intent-to-ship for Brotli content-encoding restricted it to HTTPS connections, so on plain HTTP your visitors negotiate gzip or identity even if you configured Brotli.

Support is a dated global estimate, not your audience

As a dated global-usage estimate from caniuse, read 21 November 2026: Brotli sits at 97.37% and Zstandard at 84.27%. Those are worldwide averages across all sites and devices - they are not your audience. Your own access logs or analytics, grouped by the browsers that actually hit you, are the authority for what share of your visitors send br in Accept-Encoding. Whatever that share is, gzip remains the fallback they all negotiate from, and identity remains a valid answer.

Two warnings before you turn the dial

First, MDN's Content-Encoding documentation: compressing already-compressed media such as .zip or .jpeg is usually counterproductive because it can increase file size - scope your compression to text types (HTML, CSS, JavaScript, JSON, SVG, plain text). Second, a security caveat for dynamic compression: the BREACH attack (documented by its researchers at breachattack.com) showed that when a compressed response mixes a secret such as a CSRF token with attacker-chosen input, the attacker can infer the secret from compressed response sizes. If a page reflects user-supplied input next to secrets, reflect on that before compressing it dynamically; static public assets carry no such concern.

How the choice usually plays out

Static assets (your CSS, JS, fonts, prebuilt HTML): precompress with Brotli at quality 11 at build time, keep the gzip versions as fallback, and let the negotiation sort it out - encoding cost is paid once, at build. Dynamic text (server-rendered HTML, JSON APIs): gzip at a low level or Brotli around the server defaults (ngx_brotli's 6) keeps CPU sane; go higher only if you measure the trade on your hardware. Behind a CDN like Cloudflare, check what is already enabled for your text types before adding origin compression - double work buys nothing. And keep Zstandard on the watchlist: it is newer, less supported on the dated global estimate, and available on Cloudflare through Compression Rules if your audience skews modern.

Sources, all read 21 November 2026: RFC 1952, GZIP file format (May 1996) and RFC 7932, Brotli (July 2016); MDN, Content-Encoding (br/gzip/zstd meanings; already-compressed media can grow); MDN, Accept-Encoding and Vary (negotiation and cache separation); google/brotli README ("similar in speed with deflate but offers more dense compression"; MIT license; stream format caveats) and brotli encode.h (quality 0-11, library default 11); nginx gzip module (off by default; comp_level 1-9, default 1) and google/ngx_brotli (filter + static modules; comp_level default 6); Cloudflare docs, Content compression (Gzip/Brotli/Zstandard for listed text types; Zstandard via Compression Rules); Chromium blink-dev, Intent to Ship: Brotli Accept-Encoding (Brotli restricted to HTTPS connections); caniuse brotli and caniuse zstd (dated global-usage estimates 97.37% / 84.27%, 21 November 2026); breachattack.com (compression side-channel when secrets mix with attacker-chosen input).

Frequently asked questions

Is Brotli supported everywhere yet?

Not literally everywhere, but caniuse's dated global-usage estimate was 97.37% on 21 November 2026. Treat that as a worldwide average, not your audience - your own logs show what share of your visitors send br in Accept-Encoding. gzip remains the baseline clients fall back to, and an uncompressed identity response is a valid outcome when nothing matches.

Is Brotli always smaller than gzip?

Google's README claims Brotli is "similar in speed with deflate but offers more dense compression", and it was designed for denser output - but the actual difference depends on your content and the quality levels you compare. Measure on your own assets: compress your real CSS/JS/HTML at the levels you would actually deploy and compare bytes, not benchmark folklore.

Why doesn't my nginx serve Brotli?

nginx ships the gzip module in core (off by default, gzip_comp_level 1-9, default 1) but not Brotli. For Brotli you build or install Google's ngx_brotli, which comes as two modules: a filter for on-the-fly compression (default brotli_comp_level 6) and a static module for serving pre-compressed .br files.

Does my CDN already handle this?

Check before configuring your origin. Cloudflare's documentation says it serves Gzip, Brotli and Zstandard to supporting browsers for a list of text content types, with Zstandard enabled through Compression Rules - so visitors may already get compressed responses even with an uncompressed origin. Also note Chromium restricts Brotli content-encoding to HTTPS connections.

Should I compress JSON API responses?

JSON is text and compresses well, but think about CPU level (low gzip level or mid-range Brotli for on-the-fly) and about content: the BREACH attack showed that responses mixing secrets like CSRF tokens with attacker-controlled input can leak the secret through compressed sizes. Public, cacheable API responses compress safely; authenticated responses that reflect user input next to secrets deserve a second look.

Is gzip obsolete?

No. It is the widely supported fallback clients negotiate from, it is cheap to encode at low levels, and it is the only option on plain HTTP (Chromium restricts Brotli to HTTPS). Even a site that serves Brotli to 97% of visitors keeps gzip for the rest - the two formats coexist in one setup, which is why this is a configuration question, not a migration.