Compression Rules
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.
Cloudflare provides you with rules templates for common use cases.
-
In the Cloudflare dashboard, go to the Rules Overview page.
Go to Overview -
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:
Compression Rules are available in all Cloudflare plans.
| Free | Pro | Business | Enterprise | |
|---|---|---|---|---|
Availability | Yes | Yes | Yes | Yes |
Number of rules | 10 | 25 | 50 | 300 |
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 |
-
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-encodingrequest header), the response will not be compressed. -
If a compression rule matches but the origin server's response includes a
cache-control: no-transformHTTP 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.
When troubleshooting Compression Rules, use Cloudflare Trace to determine if a rule is triggering for a specific URL.