Compression Rules
import { Render } from "~/components";
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.
<Render file="rules-requirements" product="rules" params={{ sentenceIntro: "Compression Rules require" }} />
Get started
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-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.
<Render file="troubleshoot-rules-with-trace" product="rules" params={{ rulesFeatureName: "Compression Rules" }} />
谢谢你的反馈!