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 there is a match for a compression rule configured with several compression algorithms, the selected algorithm is the first one supported by the website visitor, according to the received accept-encoding
HTTP header. If multiple compression rules match, the last rule wins.
Cloudflare provides you with rules templates for common use cases. In the dashboard, go to your zone > Rules > Templates and 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. Users in the Free plan will gradually get access throughout 2024.
Free | Pro | Business | Enterprise | |
---|---|---|---|---|
Availability | Yes | Yes | Yes | Yes |
Number of rules | 10 | 25 | 50 | 125 |
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 there is a match for a compression rule but the client does not support any of the compression algorithms configured in the rule (according to the provided
accept-encoding
request header), the response sent to the client will not be compressed. -
If there is a match for a compression rule but the response sent from the origin server contains a
cache-control: no-transform
HTTP header, the compression rule will not perform any changes to the response.
When troubleshooting compression rules, use Cloudflare Trace to determine if a rule is triggering for a specific URL.