Compression Rules

Last updated Aug 14, 2026 Use Compression Rules to customize the compression applied to responses from Cloudflare's global network to your website visitors, based on the file extension and content type. Compression Rules are powered by the Ruleset Engine.

Cloudflare compresses some responses by default, based on the content type. With Compression Rules, you can customize the default behavior, which includes defining preferred compression algorithms for particular file types.

When a compression rule matches and lists several compression algorithms (such as gzip and Brotli), Cloudflare selects the first algorithm from your list that the visitor's browser supports. Cloudflare determines browser support from the accept-encoding HTTP request header, which browsers send automatically to indicate which compression formats they can decompress. If multiple compression rules match the same request, the last matching rule takes precedence.

Note

Compression Rules require that you proxy the DNS records of your domain (or subdomain) through Cloudflare.

Get started

Cloudflare provides you with rules templates for common use cases.

  1. In the Cloudflare dashboard, go to the Rules Overview page. Go to Overview ↗
  2. Select Templates, and then select one of the available templates.

You can also refer to the Examples gallery in the developer docs.

Alternatively, follow the instructions in the following pages to get started:


Availability

Compression Rules are available in all Cloudflare plans.

Free Pro Business Enterprise
Availability Yes Yes Yes Yes
Number of rules 10 25 50 300

Relevant fields

The following fields are commonly used in expressions of compression rules:

Field in Expression Builder Field name
Media Type http.response.content_type.media_type
File extension http.request.uri.path.extension
N/A raw.http.request.uri.path.extension

Important remarks

  • If a compression rule matches but the visitor's browser does not support any of the compression algorithms configured in the rule (based on the accept-encoding request header), the response will not be compressed.
  • If a compression rule matches but the origin server's response includes a cache-control: no-transform HTTP header, the compression rule will not modify the response. Origin servers use this header to indicate that intermediaries (like Cloudflare) should not alter the response body.

Troubleshooting

When troubleshooting Compression Rules, use Cloudflare Trace to determine if a rule is triggering for a specific URL.

Was this helpful?

YesNo

On this page

Compression Rules - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/rules/compression-rules/#page","headline":"Compression Rules","description":"Customize response compression algorithms for specific content types and file extensions.","url":"https://developers.cloudflare.com/rules/compression-rules/","inLanguage":"en","image":"https://developers.cloudflare.com/rules/compression-rules/og.png?v=f1ef0d1f81d1c46e","dateModified":"2026-08-14","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Create compression rules using the Rulesets API. title: Create a compression rule via API image: https://developers.cloudflare.com/rules/compression-rules/create-api/og.png?v=7118ec11dc2f2548


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/rules/llms.txt
Use this file to discover all available pages before exploring further.