Skip to content

Use Gzip compression for CSV files

Create a compression rule to set Gzip compression as the preferred compression method for CSV files.

The following example rule will configure Gzip compression as the preferred compression method for CSV files. If the visitor does not support this algorithm, Cloudflare will try to compress the response using a different algorithm supported by the visitor.

Example

When incoming requests match

  • Custom filter expression:

    • File extension equals csv

Then

  • Compression options: Custom
  • Define a custom order for compression types: Gzip, Auto

Example API request

The following example sets the rules of an existing entry point ruleset (with ID {ruleset_id}) for the http_response_compression phase to a single compression rule, using the Update a zone ruleset operation:

Terminal window
curl --request PUT \
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"rules": [
{
"expression": "http.request.uri.path.extension eq \"csv\"",
"action": "compress_response",
"action_parameters": {
"algorithms": [
{ "name": "gzip" },
{ "name": "auto" }
]
}
}
]
}'