Loading...

Performance · 7 min read

Brotli vs Gzip: which compression should your site use?

Every text file your site serves — HTML, CSS, JavaScript, JSON — can travel at a fraction of its size if the server compresses it first. Gzip has done this job since the nineties; Brotli, Google's newer algorithm, compresses the same files noticeably smaller. This guide explains how the negotiation works, where Brotli's advantage is real and where it is marketing, what must never be compressed, and how to check with one command what your site actually sends.

Updated

Brotli vs Gzip: which compression should your site use?

How HTTP compression actually works

Compression on the web is a quiet negotiation that happens on every request. The browser announces what it can decompress in an Accept-Encoding header — modern ones send gzip and br. The server picks one, compresses the response body, and labels it with Content-Encoding so the browser knows how to unpack it. Neither your application code nor your HTML changes; the translation happens entirely in transit.

The payoff is large because text compresses extremely well. A 100 KB HTML page commonly travels as 20 KB with Gzip; a JavaScript bundle often shrinks by three quarters. For visitors on slow or mobile connections that difference is the visible part of your load time — which is why compression is the rare optimization that is nearly free and nearly always right for text.

What Brotli actually improves

Brotli's edge comes from two design choices: a smarter format, and a built-in dictionary of strings that appear constantly on the web — HTML tags, CSS property names, common JavaScript tokens. Web text is exactly what it was tuned for, and on it Brotli typically produces files 15-20% smaller than Gzip at the compression levels servers use in real time.

Keep the honest frame, though: that is 15-20% on top of Gzip's existing 70-80% reduction. If a page travels at 20 KB gzipped, Brotli makes it roughly 16-17 KB. Worth having — it compounds across every asset and every visitor — but it is a refinement, not a revolution. If you read benchmark charts claiming dramatic differences, check whether they compare Brotli's slowest, highest-effort level against Gzip's default; at those settings Brotli is too slow to run per-request and is used for precompressing static files instead.

Compatibility stopped being a concern years ago: effectively every current browser sends br in its Accept-Encoding, and the negotiation means the rare old client that does not simply gets Gzip. There is no downside case for the visitor.

What must never be compressed

The mirror rule matters just as much: compressing already-compressed bytes wastes CPU and often makes files slightly larger. Images (JPEG, PNG, WebP, AVIF), video and audio, fonts in WOFF2, ZIP archives, PDFs with embedded images — their formats already squeezed out the redundancy. There is nothing left for Gzip or Brotli to find.

This is why compression is configured by content type, and why a blanket "compress everything" rule is a small but real mistake. The practical split: text types on (HTML, CSS, JS, JSON, XML, SVG), binary media off. SVG is the one image format that belongs in the text column — it is XML, and it compresses beautifully.

Where it should run: the edge, not your app server

Brotli vs Gzip: which compression should your site use? — Where it should run: the edge, not your app server
Domains & Rules → Optimization: account-wide image optimization (WebP or WebP + AVIF) and automatic Brotli/gzip compression for each domain.

Compression costs CPU on every response, so where it runs decides whose CPU pays. When the edge compresses, your origin spends nothing on it: the edge keeps the uncompressed response in its cache and compresses each response on the way out.

On cdn.com.tr this needs no setup: compression is applied automatically to text responses, Brotli for browsers that support it and gzip for the others, and it is the same for every rule of a domain rather than set per rule — the Compression card under Domains & Rules → Optimization shows it for each domain. The edge picks what to compress by content type — HTML, CSS, JavaScript, JSON, XML and SVG among them — and sends JPEG, PNG and WebP images, video, WOFF2 fonts and zip archives as they are, which is exactly the split the previous section argued for.

Verify what you actually send

Assumptions about compression are wrong often enough that the check is worth thirty seconds. Ask for a page twice with different Accept-Encoding offers and read the Content-Encoding that comes back. While you are there, compare the transferred sizes — the difference is your saving, measured rather than believed.

One caveat when testing through cdn.com.tr: ask with a GET, as below, not a HEAD request (curl -I). The edge compresses the response body on the way out, and a HEAD answer has no body, so it comes back without a Content-Encoding even when the same page is served compressed.

Two requests, two offers — read what comes back

# what does the server send when offered brotli?
curl -s -o /dev/null -D - -H 'Accept-Encoding: br' https://example.com/ | grep -i content-encoding

# and when offered only gzip?
curl -s -o /dev/null -D - -H 'Accept-Encoding: gzip' https://example.com/ | grep -i content-encoding

# compare actual transferred bytes (compressed vs uncompressed)
curl -so /dev/null -H 'Accept-Encoding: br' -w 'brotli:  %{size_download} bytes\n' https://example.com/
curl -so /dev/null -H 'Accept-Encoding: identity' -w 'plain:   %{size_download} bytes\n' https://example.com/

How to set it up

Step-by-step guides in the help centre:

Frequently asked questions

Should I enable Brotli and Gzip together?

Yes — that is the normal setup. The negotiation picks Brotli for browsers that offer br and falls back to Gzip for the rest. Enabling both is a strict improvement over either alone.

Does compression slow my server down?

It costs CPU, but at the levels used per-request the cost is small against the bandwidth saved — and when the edge compresses, your origin pays nothing for it at all: the edge keeps the uncompressed copy in its cache and compresses each response on the way out.

Why does my image CDN traffic show no compression?

Because that is correct: JPEG, PNG, WebP and AVIF are already compressed formats, and re-compressing them wastes CPU for zero (sometimes negative) gain. Compression is for text. If you want smaller images, the lever is format and sizing — WebP/AVIF conversion — not Content-Encoding.

Do I need to change my website code to use Brotli?

No. Compression is negotiated between browser and server/edge per request; your HTML, CSS and JavaScript are untouched. On cdn.com.tr it is automatic for every domain, and the edge handles the rest.