murattunalı.
Reading

gzip or Brotli.

Brotli typically produces output 15–20 per cent smaller than gzip on text files, but compression costs more.

HTTP compression means the server shrinks a file before sending it and the browser unpacks it. The gain is large on text files because HTML, CSS and JavaScript contain a great deal of repetition, and removing repetition is exactly what compression algorithms do.

Where the difference comes from

Brotli uses a larger history window than gzip and a built-in dictionary of strings that occur frequently on the web. The dictionary helps most with small files: in a CSS file of a few kilobytes gzip has too little repetition to learn from, while Brotli draws on a ready-made dictionary.

The cost is processor time. The highest Brotli level costs many times what gzip costs, and for a server compressing on the fly on every request that cost shows up in the time to first byte. The answer is to compress files in advance: on a static site the cost is paid once at build time. We explain what the time to first byte is in a separate guide.

The decision in practice

This is a configuration, not a choice. The server offers both encodings, the browser declares what it supports through the Accept-Encoding header, and the server picks the best one. On most modern hosting providers both are on by default.

The real decision lies elsewhere: what gets compressed. Compressing an already-compressed image brings no gain and burns processor time. The right list is the text types — HTML, CSS, JavaScript, SVG, JSON, plain text. We describe the definition of the concept and the caching policy separately.

If you want your own site measured and fixed at the source, our Core Web Vitals optimization starts from real-user data and delivers LCP, INP and CLS against a budget.

Criterion

gzip

Browser support Universal — since HTTP/1.1

Size on text files Baseline

Compression cost Low

Static pre-compression Supported

On-the-fly compression Cheap

Gain on binary files Negligible

Negotiation Accept-Encoding: gzip

Brotli

Browser support All modern browsers; absent on very old clients

Size on text files Typically 15–20 % smaller

Compression cost Markedly higher at the top levels

Static pre-compression Supported — the highest level belongs here, the cost is paid once

On-the-fly compression Expensive at high levels; servers use a middle setting

Gain on binary files Negligible — images and video are already compressed

Negotiation Accept-Encoding: br — the server offers both, the client chooses

gzip or Brotli
CriteriongzipBrotli
Browser supportUniversal — since HTTP/1.1All modern browsers; absent on very old clients
Size on text filesBaselineTypically 15–20 % smaller
Compression costLowMarkedly higher at the top levels
Static pre-compressionSupportedSupported — the highest level belongs here, the cost is paid once
On-the-fly compressionCheapExpensive at high levels; servers use a middle setting
Gain on binary filesNegligibleNegligible — images and video are already compressed
NegotiationAccept-Encoding: gzipAccept-Encoding: br — the server offers both, the client chooses

FREQUENTLY ASKED QUESTIONS

Which one should I choose?

Both. The server offers both and the client takes what it supports; a browser with Brotli gets Brotli, one without falls back to gzip. The choice is an order of preference, not an exclusion.

Is it worth compressing images?

No. AVIF, WebP, JPEG and PNG are already compressed formats; applying HTTP compression on top barely reduces the size and adds processor cost.

How much gain should I expect?

On text-heavy files the gain is large, but the ratio depends on the content. This site’s main stylesheet is 67,400 bytes at source and drops to 12,415 bytes compressed, under a fifth of its size.

SOURCES