Skip to content

Commit 81bb7df

Browse files
pedrosousaelithrar
authored andcommitted
[Rules] Zstandard support / Update availability (#16876)
* Add Zstandard compression * Add changelog entry
1 parent 6c1a037 commit 81bb7df

File tree

13 files changed

+158
-123
lines changed

13 files changed

+158
-123
lines changed

.github/styles/config/vocabularies/cloudflare/accept.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ Workers
4040
VMware
4141
VPN
4242
YubiKey
43+
Zstandard
44+
Zstd

src/content/changelogs/rules.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ productLink: "/rules/"
55
productArea: Application performance
66
productAreaLink: /fundamentals/reference/changelog/performance/
77
entries:
8+
- publish_date: "2024-09-17"
9+
title: Compression Rules available to all plans with Zstandard support
10+
description: |-
11+
[Compression Rules](/rules/compression-rules/) now support Zstandard compression and are available in all Cloudflare plans. Users in the Free plan will gradually get access throughout 2024.
12+
813
- publish_date: "2024-09-13"
914
title: Snippets now available in beta
1015
description: |-

src/content/docs/rules/compression-rules/create-api.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@ sidebar:
66
head:
77
- tag: title
88
content: Create a compression rule via API
9-
109
---
1110

12-
import { Render } from "~/components"
11+
import { Render } from "~/components";
1312

1413
Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create a compression rule via API.
1514

1615
## Basic rule settings
1716

1817
When creating a compression rule via API, make sure you:
1918

20-
* Set the rule action to `compress_response`.
21-
* Define the parameters in the `action_parameters` field according to the [settings](/rules/compression-rules/settings/#api-configuration-settings) you wish to override for matching requests.
22-
* Deploy the rule to the `http_response_compression` phase at the zone level.
19+
- Set the rule action to `compress_response`.
20+
- Define the parameters in the `action_parameters` field according to the [settings](/rules/compression-rules/settings/#api-configuration-settings) you wish to override for matching requests.
21+
- Deploy the rule to the `http_response_compression` phase at the zone level.
2322

2423
## Procedure
2524

26-
<Render file="rules-creation-workflow" params={{ one: "a compression rule", two: "http_response_compression" }} />
25+
<Render
26+
file="rules-creation-workflow"
27+
params={{ one: "a compression rule", two: "http_response_compression" }}
28+
/>
2729

28-
## Example requests
30+
## Examples
2931

30-
Refer to the [Rules examples gallery](/rules/compression-rules/examples/) for example API requests.
32+
For example API requests, refer to the [Examples gallery](/rules/compression-rules/examples/).

src/content/docs/rules/compression-rules/create-dashboard.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ sidebar:
66
head:
77
- tag: title
88
content: Create a compression rule in the dashboard
9-
109
---
1110

1211
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account and domain.
1312
2. Go to **Rules** > **Compression Rules**.
1413
3. To create a new empty rule, select **Create rule**. To duplicate an existing rule, select the three dots next to it > **Duplicate**.
1514
4. Enter a descriptive name for the rule in **Rule name**.
16-
5. Under **When incoming requests match**, select if you wish to apply the rule to all incoming requests or only to requests that match a custom filter expression.
15+
5. Under **When incoming requests match**, select if you wish to apply the rule to [default content types](/speed/optimization/content/brotli/content-compression/#compression-between-cloudflare-and-website-visitors) (content types that Cloudflare compresses by default), or to requests that match a custom filter expression.
1716
6. (Optional) To define a custom expression, use the Expression Builder (specifying one or more values for **Field**, **Operator**, and **Value**) or manually enter an expression using the Expression Editor. For more information, refer to [Edit rule expressions](/ruleset-engine/rules-language/expressions/edit-expressions/).
18-
7. Under **Compression options**, set the [compression options](/rules/compression-rules/settings/#dashboard-configuration-settings) for requests matching the rule expression.
17+
7. Under **Compression options**, set the [compression options](/rules/compression-rules/settings/#dashboard-configuration-settings).
1918
8. To save and deploy your rule, select **Deploy**. If you are not ready to deploy your rule, select **Save as Draft**.

src/content/docs/rules/compression-rules/examples/disable-all-brotli.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ description: Create a compression rule to turn off Brotli compression for all
99
incoming requests of a given zone.
1010
---
1111

12-
import { Example } from "~/components";
12+
import { Example, TabItem, Tabs } from "~/components";
13+
14+
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
1315

1416
The following example rule will disable Brotli compression for all incoming requests of a given zone. The only available compression algorithm will be Gzip.
1517

@@ -28,7 +30,7 @@ The following example rule will disable Brotli compression for all incoming requ
2830

2931
If the client does not support Gzip compression, the response will be uncompressed.
3032

31-
## Example API request
33+
</TabItem> <TabItem label="API">
3234

3335
The following example sets the rules of an existing [entry point ruleset](/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](/api/operations/updateZoneRuleset) operation:
3436

@@ -51,3 +53,5 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
5153
]
5254
}'
5355
```
56+
57+
</TabItem> </Tabs>

src/content/docs/rules/compression-rules/examples/disable-compression-avif.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ description: Create a compression rule to turn off compression for AVIF images,
1111
request.
1212
---
1313

14-
import { Example } from "~/components";
14+
import { Example, TabItem, Tabs } from "~/components";
15+
16+
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
1517

1618
The following example rule will disable compression for AVIF images, based on either the content type or the file extension specified in the request.
1719

@@ -30,11 +32,11 @@ The following example rule will disable compression for AVIF images, based on ei
3032

3133
</Example>
3234

33-
## Example API request
35+
</TabItem> <TabItem label="API">
3436

3537
The following example sets the rules of an existing [entry point ruleset](/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](/api/operations/updateZoneRuleset) operation:
3638

37-
```bash
39+
```bash wrap
3840
curl --request PUT \
3941
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
4042
--header "Authorization: Bearer <API_TOKEN>" \
@@ -53,3 +55,5 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
5355
]
5456
}'
5557
```
58+
59+
</TabItem> </Tabs>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
pcx_content_type: example
3+
summary: Create a compression rule to turn on Zstandard compression for response content types where Cloudflare applies compression by default.
4+
products:
5+
- Compression Rules
6+
title: Enable Zstandard compression for default content types
7+
description: Create a compression rule to turn on Zstandard compression for response content types where Cloudflare applies compression by default.
8+
---
9+
10+
import { Example, TabItem, Tabs } from "~/components";
11+
12+
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
13+
14+
The following example rule will turn on Zstandard compression for response content types where [Cloudflare applies compression by default](/speed/optimization/content/brotli/content-compression/). If the client does not support Zstandard compression, it will use Brotli or Gzip compression as a fallback.
15+
16+
<Example>
17+
18+
**When incoming requests match**
19+
20+
- Custom filter expression:
21+
22+
- _Media Type_ _is in_ `text/html, text/richtext, text/plain, text/css, text/x-script, text/x-component, text/x-java-source, text/x-markdown, application/javascript, application/x-javascript, text/javascript, text/js, image/x-icon, image/vnd.microsoft.icon, application/x-perl, application/x-httpd-cgi, text/xml, application/xml, application/rss+xml, application/vnd.api+json, application/x-protobuf, application/json, multipart/bag, multipart/mixed, application/xhtml+xml, font/ttf, font/otf, font/x-woff, image/svg+xml, application/vnd.ms-fontobject, application/ttf, application/x-ttf, application/otf, application/x-otf, application/truetype, application/opentype, application/x-opentype, application/font-woff, application/eot, application/font, application/font-sfnt, application/wasm, application/javascript-binast, application/manifest+json, application/ld+json, application/graphql+json, application/geo+json`
23+
24+
**Then**
25+
26+
- **Compression options**: Custom
27+
- **Define a custom order for compression types**: `Zstandard`, `Brotli`, `Gzip`
28+
29+
</Example>
30+
31+
</TabItem> <TabItem label="API">
32+
33+
The following example sets the rules of an existing [entry point ruleset](/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](/api/operations/updateZoneRuleset) operation:
34+
35+
```bash wrap
36+
curl --request PUT \
37+
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
38+
--header "Authorization: Bearer <API_TOKEN>" \
39+
--header "Content-Type: application/json" \
40+
--data '{
41+
"rules": [
42+
{
43+
"expression": "(http.response.content_type.media_type in {\"text/html\" \"text/richtext\" \"text/plain\" \"text/css\" \"text/x-script\" \"text/x-component\" \"text/x-java-source\" \"text/x-markdown\" \"application/javascript\" \"application/x-javascript\" \"text/javascript\" \"text/js\" \"image/x-icon\" \"image/vnd.microsoft.icon\" \"application/x-perl\" \"application/x-httpd-cgi\" \"text/xml\" \"application/xml\" \"application/rss+xml\" \"application/vnd.api+json\" \"application/x-protobuf\" \"application/json\" \"multipart/bag\" \"multipart/mixed\" \"application/xhtml+xml\" \"font/ttf\" \"font/otf\" \"font/x-woff\" \"image/svg+xml\" \"application/vnd.ms-fontobject\" \"application/ttf\" \"application/x-ttf\" \"application/otf\" \"application/x-otf\" \"application/truetype\" \"application/opentype\" \"application/x-opentype\" \"application/font-woff\" \"application/eot\" \"application/font\" \"application/font-sfnt\" \"application/wasm\" \"application/javascript-binast\" \"application/manifest+json\" \"application/ld+json\" \"application/graphql+json\" \"application/geo+json\"})",
44+
"action": "compress_response",
45+
"action_parameters": {
46+
"algorithms": [
47+
{ "name": "zstd" },
48+
{ "name": "brotli" },
49+
{ "name": "gzip" }
50+
]
51+
}
52+
}
53+
]
54+
}'
55+
```
56+
57+
</TabItem> </Tabs>

src/content/docs/rules/compression-rules/examples/gzip-for-csv.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ description: Create a compression rule to set Gzip compression as the preferred
99
compression method for CSV files.
1010
---
1111

12-
import { Example } from "~/components";
12+
import { Example, TabItem, Tabs } from "~/components";
13+
14+
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
1315

1416
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.
1517

@@ -28,7 +30,7 @@ The following example rule will configure Gzip compression as the preferred comp
2830

2931
</Example>
3032

31-
## Example API request
33+
</TabItem> <TabItem label="API">
3234

3335
The following example sets the rules of an existing [entry point ruleset](/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](/api/operations/updateZoneRuleset) operation:
3436

@@ -52,3 +54,5 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
5254
]
5355
}'
5456
```
57+
58+
</TabItem> </Tabs>

src/content/docs/rules/compression-rules/examples/only-brotli-url-path.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ description: Create a compression rule to set Brotli as the only supported
99
compression algorithm for a specific URI path.
1010
---
1111

12-
import { Example } from "~/components";
12+
import { Example, TabItem, Tabs } from "~/components";
13+
14+
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
1315

1416
The following example rule will configure only Brotli compression for a specific URI path.
1517

@@ -30,7 +32,7 @@ The following example rule will configure only Brotli compression for a specific
3032

3133
Since the rule configuration does not include _Auto_ at the end of the custom algorithms list, the response will be uncompressed if the web visitor does not support Brotli.
3234

33-
## Example API request
35+
</TabItem> <TabItem label="API">
3436

3537
The following example sets the rules of an existing [entry point ruleset](/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](/api/operations/updateZoneRuleset) operation:
3638

@@ -53,3 +55,5 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id} \
5355
]
5456
}'
5557
```
58+
59+
</TabItem> </Tabs>

src/content/docs/rules/compression-rules/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Alternatively, follow the instructions in the following pages to get started:
3131

3232
## Availability
3333

34-
Compression Rules are available to Enterprise customers.
34+
Compression Rules are available in all Cloudflare plans. Users in the Free plan will gradually get access throughout 2024.
3535

3636
<FeatureTable id="rules.compression_rules" />
3737

@@ -47,7 +47,7 @@ The following fields are commonly used in expressions of compression rules:
4747

4848
## Important remarks
4949

50-
- 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.
50+
- 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.
5151

5252
- 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.
5353

0 commit comments

Comments
 (0)