Compression Rules settings
Compression Rules support the configuration settings covered in the following sections.
Dashboard configuration settings
Enable compression
Compresses the response according to the algorithms supported by the website visitor (if any). Cloudflare will define the order of preference for the compression algorithms, which may change in the future.
Disable compression
Disables compression for matching requests. Also disables Cloudflare’s default compression behavior.
Custom
Defines a custom order for compression algorithms.
Allowed values are the following:
- Gzip: Use the GZIP compression algorithm, if supported by the website visitor.
- Brotli: Use the Brotli compression algorithm, if supported by the website visitor.
- Auto: Compress the response according to the algorithms supported by the website visitor (if any). Cloudflare will define the order of preference for the compression algorithms, which may change in the future. Has the same behavior of the Enable compression option.
- Default: Use Cloudflare’s default compression behavior, which depends on the response content type.
If you specify only Gzip and/or Brotli and no algorithm matches, the response will have no compression. To configure a fallback compression mechanism, add Auto to the list.
API configuration settings
The configuration object supported by the compress_response
action has the following format:
"action_parameters": { "algorithms": [ { "name": "<VALUE1>" }, { "name": "<VALUE2>" }, // ... ]
}
The algorithms
list must contain at least one item.
The supported algorithm values are:
gzip
: Use the GZIP compression algorithm, if supported by the website visitor.brotli
: Use the Brotli compression algorithm, if supported by the website visitor.none
: Do not use any compression algorithm.auto
: Compress the response according to the algorithms supported by the website visitor (if any). Cloudflare will define the order of preference for the compression algorithms, which may change in the future.default
: Use Cloudflare’s default compression behavior, which depends on the response content type.
If you include none
, default
, or auto
in the list, it must be the last value in the list.
When you specify only the gzip
and/or brotli
algorithms, if no algorithm matches then the response will have no compression. To configure a fallback compression mechanism, add auto
to the list.
Examples
The following API examples implement the same behavior as the options in the Cloudflare dashboard. To compress a response according to the algorithms supported by the visitor (if any), set the The To disable compression for matching requests, set the This example sets the preferred compression algorithm to Brotli, using GZIP as a fallback. If the visitor does not support any of these algorithms, try to compress the response according to the algorithms supported by the website visitor (if any).Enable compression
algorithms
list to a single algorithm: "auto"
.auto
algorithm will always apply compression to the response as long as the website visitor supports compression. Cloudflare will define the order of preference for the compression algorithms, which may change in the future.Disable compression
algorithms
list to a single algorithm: "none"
.Define a custom order for compression algorithms