Compress the Content

Last update:2026-05-09 10:30:49

In the context of HTTP protocol requests, compressing response data can effectively reduce the amount of data transferred, achieving reduced response times, saving server-side network bandwidth, and enhancing client-side performance. If your website does not support the compression of response data, but the user’s request header contains Accept-Encoding and the desired compression format is supported by CDNetworks, you can easily configure on our platform to return the files in the required compressed format to the client.

How to Configure Compression Rules

  1. Log in to the CDNetworks Console and select the appropriate product.
  2. Navigate to the Configuration, locate the domain you wish to configure, and click on Edit Configuration at the top or Edit to the right of the domain image.png.
  3. Enter the configuration modification page, find the Compression Rules under Advanced Settings, and click the Edit button;
  4. On the rule editing page, you can easily add the following configuration options based on your needs.

Apply to

Parameter Description
All Requests Indicates that all requests initiated towards the associated domain are applicable to this rule.
Only Homepage This rule is applicable only to requests in the root directory, e.g.,http://domain/or https://domain/.
Specified File Type This rule applies to the requests for specified file types, you can choose from listed ones or customize your file types in this field. Separate multiple file types with ;, e.g.,ace;aac.
Specified URL Path You can set the request for a specific URI to execute this rule. Multiple URIs can be configured, separated by a newline character;
Note that the URIs you enter do not include http:// or https://, only configure the URI part, e.g.,the complete URL is https://domain/browse/index.html, you only need to configure /browse/index.html.
Specified Directory This rule applies to all requests aimed at specified directories while directories must begin and end with a / and can be composed of any combination of letters, numbers, and certain special symbols (including underscores, hyphens, percentage signs, and dots), e.g.,/file/1%1/, indicates that the rule applies to requests for the directoryhttp://domain/file/1%1/and all files within it.
Please note that, you need to separate multiple directories with a line break.
URL Pattern (Regex) You can also choose to directly enter a regular expression, not required to start with /. The platform will automatically prefix the URL with ^https?://[^/]/, e.g.,.*.jpg$, indicating that requests for JPG files across all domains associated with this rule will match this policy.

MIME Types
If the Compression Rules is enabled but this parameter is left empty by default, it means only text files type (one of MIME types) will be compressed; you can customize multiple file types for compression, separated by semicolons, such as application/x-javascript;text/css;application/json etc.; whereas common image file types PNG, JPG, JPEG and audio-video file types MP4, AVI, WMV etc., are already default compressed, it’s not recommended to configure these file types in this setting.

Compression Types Configuration
Currently, you can configure two types of compression types on the CDNetworks CDN platform, as follows:

  • Gzip Compression: it is an optional setting which indicates regular compress responses based on the Accept-Encoding request header specified by the client, currently supporting two compression formats: gzip, deflate, with the default value being No, i.e., regular compression response is not enabled;
  • Brotli Compression: If the client request carries the request header Accept-Encoding: br, then br compression is performed; brotli compression is only compatible with specific browsers, so you need to verify it with the browsers you intend to support before enabling this configuration.

After you have completed setting the configurations, please click OK and then select Next to submit your settings. To minimize any potential disruptions to your production environment, we strongly recommend conducting a Pre-deploy test in a staging environment. This crucial step ensures that your configurations are accurate before they go live. Once you have verified the accuracy of the settings, click Deploy Now to implement them in the live environment. The configurations typically become effective within 3-5 minutes. For comprehensive guidance on pre-deployment testing and to verify the effectiveness of your configurations, please consult the tutorial Deploy the Configurations to Staging Environment for Validation.

Best Practices

Example 1: For all requests, compress responses for specific MIME types
For the domain associated with this rule, if the MIME type of the resource requested by the user is application/x-javascript, it will be compressed by the CDN servers before being returned to your users.


Notes

CDNetworks CDN platform defaults to a minimum file size of 2KB for compression; files smaller than this size will not be compressed even if you have enabled Gzip Compression.

Is the content of this document helpful to you?
Yes
I have suggestion
Submitted successfully! Thank you very much for your feedback, we will continue to strive to do better!