Nodea — logo

Brotli

Brotli is a lossless data-compression algorithm developed at Google and standardized as RFC 7932, designed primarily to make the web faster. It combines a modern LZ77 variant, Huffman coding and context modeling, and its signature feature is a built-in 120 KB dictionary of over 13,000 common strings drawn from natural language, HTML and code — which is why it compresses typical web assets noticeably better than gzip, usually by 15–25% for text content.

How Brotli works

Brotli exposes quality levels 0–11; higher levels produce smaller files at the cost of compression time (decompression stays fast throughout). That asymmetry dictates two deployment modes:

  • dynamic compression — for HTML generated per request, servers use levels 4–6 as a balance between transfer size and CPU load,
  • static pre-compression — CSS, JavaScript and SVG files are compressed once at build or deploy time at level 11, and the server ships the ready-made .br file with zero per-request cost.

Negotiation is standard HTTP content encoding: the browser sends Accept-Encoding: br, gzip, the server answers with Content-Encoding: br. All modern browsers support Brotli over HTTPS, and gzip remains as a fallback for legacy clients.

Practical use

Enabling Brotli is one of the cheapest performance wins available: smaller transfers directly improve First Contentful Paint and LCP, lift PageSpeed scores and cut bandwidth bills. On Nginx it is provided by the ngx_brotli module (brotli on; brotli_static on;), on Apache by mod_brotli, LiteSpeed supports it natively, and most CDNs — Cloudflare, Fastly, CloudFront — compress with Brotli at the edge. On shared hosting, support depends on the platform's server configuration, so it is worth checking before you rely on it.

Compress only text-based content types: HTML, CSS, JS, JSON, SVG, XML and fonts that are not already compressed. Re-compressing JPEG/WebP images, video or archives wastes CPU for zero gain — exclude those MIME types from the configuration.

Powiązane pojęcia

Najczęstsze pytania

Should I replace gzip with Brotli?

Enable Brotli as the preferred encoding and keep gzip as a fallback. Browsers advertise what they accept via the Accept-Encoding header, so the server automatically serves Brotli to modern clients and gzip to legacy ones — you lose nothing by running both.