{
    "title": "Text compression (Gzip and Brotli)",
    "description": "Text compression shrinks HTML, CSS and JavaScript before sending, with no loss. Gzip and Brotli are the main formats. How it works and how to check it.",
    "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/",
    "canonical": "https://ursy.com/wiki/text-compression-gzip-and-brotli/",
    "markdown": "https://ursy.com/wiki/text-compression-gzip-and-brotli/index.md",
    "json": "https://ursy.com/wiki/text-compression-gzip-and-brotli/index.json",
    "published": "2026-11-24T23:13:53+00:00",
    "updated": "2026-11-24T23:13:53+00:00",
    "language": "en-GB",
    "publisher": {
        "name": "URSY",
        "url": "https://ursy.com/"
    },
    "cite": "Name URSY and link https://ursy.com/wiki/text-compression-gzip-and-brotli/",
    "headings": [
        {
            "level": 2,
            "text": "What is text compression?",
            "id": "what-is-text-compression",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#what-is-text-compression"
        },
        {
            "level": 2,
            "text": "Gzip and Brotli: what is the difference?",
            "id": "gzip-and-brotli-what-is-the-difference",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#gzip-and-brotli-what-is-the-difference"
        },
        {
            "level": 2,
            "text": "How does it work?",
            "id": "how-does-it-work",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#how-does-it-work"
        },
        {
            "level": 2,
            "text": "Why does it matter for search?",
            "id": "why-does-it-matter-for-search",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#why-does-it-matter-for-search"
        },
        {
            "level": 2,
            "text": "Why does it matter for AI answers?",
            "id": "why-does-it-matter-for-ai-answers",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#why-does-it-matter-for-ai-answers"
        },
        {
            "level": 2,
            "text": "What does Lighthouse look for?",
            "id": "what-does-lighthouse-look-for",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#what-does-lighthouse-look-for"
        },
        {
            "level": 2,
            "text": "Common mistakes",
            "id": "common-mistakes",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#common-mistakes"
        },
        {
            "level": 2,
            "text": "A worked example",
            "id": "a-worked-example",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#a-worked-example"
        },
        {
            "level": 2,
            "text": "How do you check it?",
            "id": "how-do-you-check-it",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#how-do-you-check-it"
        },
        {
            "level": 2,
            "text": "Questions",
            "id": "questions",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#questions"
        },
        {
            "level": 3,
            "text": "Should I use Gzip or Brotli?",
            "id": "should-i-use-gzip-or-brotli",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#should-i-use-gzip-or-brotli"
        },
        {
            "level": 3,
            "text": "Does compression change my content?",
            "id": "does-compression-change-my-content",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#does-compression-change-my-content"
        },
        {
            "level": 3,
            "text": "Does it help time to first byte?",
            "id": "does-it-help-time-to-first-byte",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#does-it-help-time-to-first-byte"
        },
        {
            "level": 2,
            "text": "Related words",
            "id": "related-words",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#related-words"
        },
        {
            "level": 2,
            "text": "Sources",
            "id": "sources",
            "url": "https://ursy.com/wiki/text-compression-gzip-and-brotli/#sources"
        }
    ],
    "links": [
        {
            "text": "guide to compression in HTTP",
            "url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Compression",
            "internal": false
        },
        {
            "text": "minification",
            "url": "https://ursy.com/wiki/minification/",
            "internal": true
        },
        {
            "text": "RFC 1952",
            "url": "https://www.rfc-editor.org/rfc/rfc1952",
            "internal": false
        },
        {
            "text": "RFC 7932",
            "url": "https://www.rfc-editor.org/rfc/rfc7932",
            "internal": false
        },
        {
            "text": "Google",
            "url": "https://ursy.com/wiki/google/",
            "internal": true
        },
        {
            "text": "Content-Encoding reference",
            "url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Encoding",
            "internal": false
        },
        {
            "text": "HTTP headers",
            "url": "https://ursy.com/wiki/http-headers/",
            "internal": true
        },
        {
            "text": "cache",
            "url": "https://ursy.com/wiki/caching/",
            "internal": true
        },
        {
            "text": "CDN",
            "url": "https://ursy.com/wiki/cdn/",
            "internal": true
        },
        {
            "text": "edge cache",
            "url": "https://ursy.com/wiki/edge-cache/",
            "internal": true
        },
        {
            "text": "page speed",
            "url": "https://ursy.com/wiki/page-speed/",
            "internal": true
        },
        {
            "text": "Core Web Vitals",
            "url": "https://ursy.com/wiki/core-web-vitals/",
            "internal": true
        },
        {
            "text": "Largest Contentful Paint",
            "url": "https://ursy.com/wiki/largest-contentful-paint/",
            "internal": true
        },
        {
            "text": "Enable text compression",
            "url": "https://developer.chrome.com/docs/lighthouse/performance/uses-text-compression",
            "internal": false
        },
        {
            "text": "Google Lighthouse",
            "url": "https://ursy.com/wiki/google-lighthouse/",
            "internal": true
        },
        {
            "text": "PageSpeed Insights",
            "url": "https://ursy.com/wiki/google-pagespeed-insights/",
            "internal": true
        },
        {
            "text": "bots",
            "url": "https://ursy.com/wiki/bot-web-robot/",
            "internal": true
        },
        {
            "text": "origin server",
            "url": "https://ursy.com/wiki/origin-server/",
            "internal": true
        },
        {
            "text": "AI crawlers will slow your website",
            "url": "https://ursy.com/guides/will-ai-crawlers-slow-my-website/",
            "internal": true
        },
        {
            "text": "AI crawler",
            "url": "https://ursy.com/wiki/ai-crawler/",
            "internal": true
        },
        {
            "text": "WebP and AVIF",
            "url": "https://ursy.com/wiki/webp-and-avif/",
            "internal": true
        },
        {
            "text": "XML sitemap",
            "url": "https://ursy.com/wiki/xml-sitemap/",
            "internal": true
        },
        {
            "text": "a website is slow",
            "url": "https://ursy.com/wiki/why-your-website-is-slow/",
            "internal": true
        },
        {
            "text": "HTTP header checker",
            "url": "https://ursy.com/http-header-checker/",
            "internal": true
        },
        {
            "text": "HTTP header checker guide",
            "url": "https://ursy.com/guides/how-to-use-http-header-checker/",
            "internal": true
        },
        {
            "text": "page speed checker",
            "url": "https://ursy.com/page-speed-checker/",
            "internal": true
        },
        {
            "text": "Core Web Vitals checker",
            "url": "https://ursy.com/core-web-vitals-checker/",
            "internal": true
        },
        {
            "text": "cache checker",
            "url": "https://ursy.com/cache-checker/",
            "internal": true
        },
        {
            "text": "data size converter",
            "url": "https://ursy.com/webmaster-tools/data-size-converter/",
            "internal": true
        },
        {
            "text": "JavaScript minifier",
            "url": "https://ursy.com/webmaster-tools/javascript-minifier/",
            "internal": true
        },
        {
            "text": "asset diet report",
            "url": "https://ursy.com/pro/asset-diet-report/",
            "internal": true
        },
        {
            "text": "time to first byte",
            "url": "https://ursy.com/wiki/time-to-first-byte/",
            "internal": true
        },
        {
            "text": "Critical rendering path",
            "url": "https://ursy.com/wiki/critical-rendering-path/",
            "internal": true
        },
        {
            "text": "HTTP",
            "url": "https://ursy.com/wiki/http/",
            "internal": true
        },
        {
            "text": "CSS",
            "url": "https://ursy.com/wiki/css/",
            "internal": true
        },
        {
            "text": "HTML",
            "url": "https://ursy.com/wiki/html/",
            "internal": true
        }
    ],
    "words": 1049,
    "text": "Text compression is when a web server shrinks text files such as HTML, CSS and JavaScript before sending them, and the browser unpacks them on arrival; Gzip and Brotli are the 2 formats almost every site uses. Nothing is lost on the way. The visitor gets the exact same file, just in fewer bytes, so pages arrive faster. What is text compression? Text repeats itself. The same tags, words and code patterns appear again and again. A compression format replaces those repeats with short references. MDN’s guide to compression in HTTP calls this lossless compression: after packing and unpacking, the data matches the original byte for byte. The same guide says text can typically have as much as 60% redundancy, and that for some documents compression cuts size by up to 70%. This is not the same as minification. Minifying removes spaces and comments from the file itself. Compression packs whatever file you have for the trip. Most sites do both. Gzip and Brotli: what is the difference? Gzip Brotli Specification RFC 1952, May 1996 RFC 7932, July 2016 How it packs The DEFLATE method, with a CRC-32 check for damaged data LZ77 and Huffman coding, plus context modelling and a built-in dictionary Header value gzip br Usual role The safe fallback every client understands The first choice where the browser supports it Brotli was written by 2 engineers at Google. Its RFC says it gives efficiency comparable to the best general-purpose methods available at the time. A key trick is a static dictionary built into the format, so common words can be referenced without first appearing in the file. MDN’s Content-Encoding reference also lists zstd (Zstandard, RFC 8878) and newer dictionary-based variants, but Gzip and Brotli remain the 2 that matter for most sites. How does it work? It is a short conversation in the HTTP headers: The browser asks for a file and says which formats it can read: Accept-Encoding: br, gzip. The server picks one, compresses the body and answers with Content-Encoding: br. The server adds Vary: Accept-Encoding, so any cache in between keeps separate copies for each format. The browser unpacks the file and uses it as normal. MDN explains that the Vary header is a must here: without it, a CDN or edge cache could hand a Brotli file to a client that only reads Gzip. Why does it matter for search? Smaller files arrive sooner. That helps page speed and feeds the Core Web Vitals, especially Largest Contentful Paint, because the HTML and CSS that block the first paint get through faster. Google’s Lighthouse has long had an audit called Enable text compression. Its documentation says that in Lighthouse 13 the check moved into the Document request latency insight. Our page on Google Lighthouse explains where to find it in reports from PageSpeed Insights. Why does it matter for AI answers? AI crawlers fetch pages too, often in large numbers. Every byte you save is saved on every one of those requests. Compressed responses mean less bandwidth spent on bots and less load on your origin server. Our guide on whether AI crawlers will slow your website covers the wider picture, and our AI crawler page explains who is visiting. What does Lighthouse look for? Google’s audit page says Lighthouse gathers text-based responses that are not served with a content-encoding of br, gzip or deflate. It then compresses each with Gzip to estimate the saving. It skips files under 1.4 KiB, and files where the saving would be under 10% of the original size. Its advice: switch compression on at the server, prefer Brotli, and keep Gzip as a fallback. Common mistakes Compressing images again. MDN advises compressing everything except already-compressed files such as images, audio and video. Packing a JPEG a second time can even make it bigger. Shrink pictures with formats like WebP and AVIF instead. Forgetting the Vary header. Caches then mix up versions. Only compressing HTML. CSS, JavaScript, JSON, SVG and XML files such as your XML sitemap are text too. Testing without the request header. A test that does not send Accept-Encoding gets an uncompressed reply and wrongly concludes compression is off. Turning compression off to “fix” a plugin. Find the clash instead. It is one of the common reasons a website is slow. A worked example A small UK online shop’s product page sends a 240 KB HTML file, a 180 KB stylesheet and a 400 KB JavaScript bundle, all uncompressed. The owner switches on Brotli with Gzip as the fallback in the server settings. To check, she asks for the page from the command line: curl -sI -H \"Accept-Encoding: br, gzip\" https://www.example.co.uk/product/ The reply now includes content-encoding: br and vary: Accept-Encoding. In Chrome DevTools, with large request rows on, the Size column shows 2 figures for each file: the bytes sent over the wire on top and the unpacked size below. The bytes on the wire drop sharply. The exact saving depends on the file, which is why she measures rather than guesses. How do you check it? Run any address through our HTTP header checker and look for content-encoding in the response. Our HTTP header checker guide walks through the results. Test the full page with our page speed checker or Core Web Vitals checker to see the effect on load time. Check cache behaviour with our cache checker, including the Vary header. Turn raw byte counts into plain sizes with our data size converter, and shrink scripts first with our JavaScript minifier. For a site-wide view, our asset diet report (Pro) is being built to list heavy files page by page. Questions Should I use Gzip or Brotli? Both. Serve Brotli to clients that ask for it and Gzip to the rest. The browser’s request header decides. Does compression change my content? No. It is lossless. The unpacked file is identical to the original. Does it help time to first byte? Not directly. TTFB is about when the first byte leaves the server. Compression shortens the time to receive the rest. Related words Critical rendering path HTTP CSS HTML Sources MDN: Compression in HTTP, checked 24 November 2026 MDN: Content-Encoding header, checked 24 November 2026 RFC 7932: Brotli Compressed Data Format, July 2016, checked 24 November 2026 RFC 1952: GZIP File Format Specification 4.3, May 1996, checked 24 November 2026 Chrome for Developers: Enable text compression (Lighthouse), checked 24 November 2026 Updated 24 November 2026 by URSY.",
    "source": "https://ursy.com/wiki/text-compression-gzip-and-brotli/"
}