---
title: Use Gzip compression for CSV files · Cloudflare Rules docs
description: Create a compression rule to set Gzip compression as the preferred compression method for CSV files.
lastUpdated: 2025-04-02T13:25:58.000Z
source_url:
  html: https://77261bbd.preview.developers.cloudflare.com/rules/compression-rules/examples/gzip-for-csv/index.md
  md: https://77261bbd.preview.developers.cloudflare.com/rules/compression-rules/examples/gzip-for-csv/
---

* Dashboard

  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.

  **When incoming requests match**

  * Custom filter expression:

    * *File extension* *equals* `csv`

  **Then**

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

* API

  The following example sets the rules of an existing [entry point ruleset](https://developers.cloudflare.com/ruleset-engine/about/rulesets/#entry-point-ruleset) (with ID `{ruleset_id}`) for the `http_response_compression` phase to a single compression rule, using the [Update a zone ruleset](https://developers.cloudflare.com/api/resources/rulesets/methods/update/) operation:

  ```bash
  curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/$RULESET_ID" \
    --request PUT \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    --json '{
      "rules": [
          {
              "expression": "http.request.uri.path.extension eq \"csv\"",
              "action": "compress_response",
              "action_parameters": {
                  "algorithms": [
                      {
                          "name": "gzip"
                      },
                      {
                          "name": "auto"
                      }
                  ]
              }
          }
      ]
    }'
  ```
