Gzip and Brotli Compression

Gzip and Brotli compression are methods servers use to shrink text-based files, such as HTML, CSS, JavaScript and JSON, before sending them to the browser, which then unpacks them. This greatly reduces the data transferred and helps pages load faster.

How text compression works

Text files contain lots of repetition: the same tags, property names and words appear again and again. Compression algorithms replace repeated patterns with short references. The process is lossless, so the browser rebuilds the exact original file.

It works through a simple handshake. The browser sends an Accept-Encoding header listing the methods it supports, such as gzip, br. The server picks one and returns the file with a Content-Encoding header saying which was used.

Gzip versus Brotli

  • Gzip has been the web standard for decades. It is fast, supported everywhere and enabled by default on most hosting.
  • Brotli was developed by Google and usually produces smaller files than Gzip for the same content, especially at higher settings. All modern browsers support it over HTTPS.

A common setup is to serve Brotli to browsers that accept it and fall back to Gzip for anything else. Static files can be compressed in advance at high settings, while dynamic HTML is usually compressed on the fly at a moderate level to save server time.

Why it matters for SEO

Text compression is one of the simplest wins for page speed.

Smaller HTML, CSS and JavaScript download faster, especially on mobile networks, which helps First Contentful Paint.

Faster delivery of stylesheets and scripts also supports Largest Contentful Paint, one of the Core Web Vitals.

Googlebot supports Gzip and Brotli, so compression also reduces the bandwidth used during crawling.

How to check and enable it

  1. Run a page through PageSpeed Insights, which flags text resources served without compression.
  2. Open browser developer tools, select a file in the Network tab and look for content-encoding: br or gzip in the response headers.
  3. Enable compression in your server configuration, hosting panel or caching plugin. Many hosts and CDNs turn on Brotli with a single setting.
  4. Make sure compression covers HTML, CSS, JavaScript, JSON, XML and SVG files.

Common mistakes

  • Compressing images again: JPEG, PNG, WebP and video files are already compressed, so Gzip adds server work for little or no gain. Most servers skip these file types by default, but custom rules sometimes include them. Use image compression instead.
  • Skipping minification: compression and minification work best together.
  • Double compression: a misconfigured server and CDN can both try to compress, causing broken responses.
  • Leaving out sitemaps and APIs: large XML and JSON files benefit too.
  • Assuming it is on: many hosts enable compression by default, but not all, so always check the response headers rather than assuming.

Further reading: MDN’s guide to HTTP compression.

Key Takeaways

  • Gzip and Brotli shrink text files before they are sent to the browser.
  • Compression is lossless, so the original file is rebuilt exactly.
  • Brotli usually beats Gzip, and Gzip remains a safe fallback.
  • It is one of the easiest page speed wins available.
  • Do not apply it to images and video, which are already compressed.

Related Terms

Browse more terms in the SEO Encyclopedia.