murattunalı.

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. What the time to first byte is is written separately.

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. The definition of the concept and the caching policy are described separately.

Criterion

  1. Browser support — gzip: Universal — since HTTP/1.1 · Brotli: All modern browsers; absent on very old clients
  2. Size on text files — gzip: Baseline · Brotli: Typically 15–20 % smaller
  3. Compression cost — gzip: Low · Brotli: Markedly higher at the top levels
  4. Static pre-compression — gzip: Supported · Brotli: Supported — the highest level belongs here, the cost is paid once
  5. On-the-fly compression — gzip: Cheap · Brotli: Expensive at high levels; servers use a middle setting
  6. Gain on binary files — gzip: Negligible · Brotli: Negligible — images and video are already compressed
  7. Negotiation — gzip: Accept-Encoding: gzip · Brotli: Accept-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 12,415 bytes compressed — under a fifth.

SOURCES