Guides Guides 5 min read 973 words

Cloudflare Compression: Enable Brotli, Gzip and Zstd

Check Cloudflare compression and configure Brotli, Gzip or Zstd with Compression Rules. Verify response headers and troubleshoot uncompressed files.

Cloudflare compression reduces the amount of data transferred for eligible responses using a format the visitor's browser supports. Cloudflare already compresses some content by default; use Compression Rules when you need to customize that behavior rather than looking for the old Brotli toggle.

The earlier version of this guide walked through a Speed-menu switch. Cloudflare has deprecated that standalone Brotli setting. We now explain the current rules workflow, how to confirm the actual response encoding, and why a missing encoding header does not automatically mean your configuration is broken.

What Cloudflare compresses

Cloudflare's content-compression documentation supports Gzip, Brotli, and Zstandard for delivery to visitors. The format depends on the client's Accept-Encoding header, the zone's plan, and matching Compression Rules. Eligible content includes HTML, CSS, JavaScript, JSON, SVG, and other documented media types.

Do not interpret that as a promise that every response is compressed. Cloudflare documents content-type, size, and status restrictions. For visitor delivery, it currently compresses successful 200 responses and error responses with status 403 or 404, subject to the other requirements. A redirect response is therefore a poor test object.

Text compression is not the same as changing an image's dimensions or re-encoding a photo into a different image format. Nor does it remove unnecessary JavaScript from your application. Focus the test on an eligible text resource that the browser actually downloads.

Check the proxy and existing behavior first

Compression Rules require proxied DNS records. If the website hostname is DNS-only, its requests do not pass through Cloudflare's HTTP proxy. Our proxy guide covers that prerequisite. Confirm the particular hostname rather than assuming every record in an active zone is proxied.

Next, request a normal HTML page or stylesheet and inspect the response headers. It may already have a Content-Encoding value. In that case, first decide whether you need a rule at all. A working default configuration is not a failure simply because no manual Brotli switch was enabled.

Record any existing compression rules before changing them. Cloudflare says that when several such rules match, the last matching rule takes precedence. A new rule's effect therefore depends on the surrounding configuration, not just the options displayed in its editor.

Create a Compression Rule

  1. Sign in to Cloudflare, select the correct website, and open the Rules Overview page.
  2. Select Create rule, then Compression Rule.
  3. Optionally start from a template, but review its proposed conditions before using it.
  4. Enter a descriptive Rule name.
  5. Under When incoming requests match, choose the default content types or a custom filter expression for the intended traffic.
  6. If you need a custom expression, use the Expression Builder or Expression Editor and check the scope carefully.
  7. Under Compression options, select the required behavior. The documented options include enabling Brotli and Gzip, preferring Zstandard, disabling compression, and a custom algorithm order.
  8. Select Deploy to activate the rule, or Save as Draft if the configuration is not ready.

For a straightforward compatible configuration, Cloudflare documents Enable Brotli and Gzip compression with Brotli preferred and fallback to Gzip or uncompressed data. Its Zstandard option similarly includes fallbacks. A custom list containing only one algorithm can leave unsupported clients without compression.

Verify the encoding actually delivered

Open the browser network panel, disable the browser cache for the test, and reload a page. Choose a fresh eligible response rather than an entry served entirely from local storage. Inspect the request's Accept-Encoding and the response's Content-Encoding.

The response value identifies the transfer format: br means Brotli, gzip means Gzip, and zstd means Zstandard. Compare it with the client's advertised support and the matching rule. Do not force a conclusion from the file extension alone: the response's media type matters too.

Repeat the check for an HTML page and a stylesheet or script. A single compressed file does not establish that every file is eligible or that every path matches the same rule. Keep the resource URL and relevant headers in your notes so you can repeat the comparison after another change.

Why a response may remain uncompressed

  • The request bypasses the proxy because the hostname is DNS-only.
  • The browser does not advertise support for any algorithm allowed by the rule.
  • The response is too small, has an ineligible media type, or uses a status code Cloudflare does not compress.
  • A later matching rule changes or disables the intended behavior.
  • The origin returns Cache-Control: no-transform, which prevents a Compression Rule from modifying the response.

Cloudflare currently documents minimum response sizes of 48 bytes for Gzip and 50 bytes for Brotli and Zstandard. Do not use a tiny test response to judge a rule intended for real pages. Likewise, a missing Content-Length header is not itself evidence of failure: Cloudflare may omit it when transforming responses.

Origin compression and caching are separate

Cloudflare can receive Brotli, Gzip, or uncompressed content from the origin and deliver a different supported representation to visitors. Its documentation describes this as independent of caching. An edge cache miss does not, by itself, prove that transfer compression cannot be used.

If you also manage Apache, our origin Gzip guide addresses a different connection leg. Our Cloudflare caching guide covers stored responses, and our Auto Minify replacement guide separates code transformation from transfer encoding.

To undo an unwanted rule, disable that specific rule and retest the same eligible resources. That restores evaluation without it; other rules and Cloudflare defaults can still apply. If you are checking registration information during a wider setup, our domain lookup is available, but it cannot verify HTTP compression.

Compression FAQ

Do we need the old Brotli toggle?

No. The standalone setting is deprecated; inspect current defaults and use Compression Rules for customization.

Does compression guarantee faster pages?

No fixed speed improvement follows from an encoding header. Measure your own resources and page behavior under comparable conditions.

Sources