File compression algorithms
File compression is available if the selected content delivery optimization type is Static.
Compression algorithms are suitable for text formats, such as HTML, CSS, JS, JSON, XML, SVG, and others. The algorithms work on the same principle: they find repeating fragments in a file and replace them with links to the first encountered fragment, reducing the file size.
Compression algorithms are not suitable for processing already compressed files, such as raster images, audio and video files, and archives. To manage image quality and format (for example, convert to WebP), you can enable the Image Optimization service.
CDN supports two compression algorithms:
- Gzip is a common algorithm: it works with all HTTP protocols, supports HTTPS, and is compatible with all browsers. Gzip is enabled by default;
- Brotli is 20% more effective than Gzip, but only works over HTTPS, with modern browsers, and with certain file types. Brotli can be enabled additionally.
You can use both algorithms simultaneously. The CDN will automatically determine which one is supported by the user's browser and deliver the file compressed with the appropriate algorithm.
Gzip compression algorithm
Gzip works without restrictions:
- supports HTTP and HTTPS;
- compatible with all browsers;
- applies to all file types.
Gzip is enabled by default, and we do not recommend disabling it. If you disabled Gzip, you can enable it at any time.
Enable Gzip compression algorithm
-
In the control panel, in the top menu, click Products and select CDN.
-
In the CDN resources section, open the resource page → tab Optimization.
-
Make sure that in the Delivery optimization type section, the selected option is Static.
-
In the Compression section, select the checkbox Gzip compression.
-
Click Apply. While the settings are being applied, the resource will have the
PROCESSINGstatus. Applying other settings is not available during this time. The settings will be applied once the resource status changes toACTIVE.
Disable Gzip compression algorithm
We do not recommend disabling Gzip unless you are using an alternative compression method at the origin. Without compression, files will be transferred at their original size. This will increase load times for users and the amount of CDN traffic consumed.
-
In the control panel, in the top menu, click Products and select CDN.
-
In the CDN resources section, open the resource page → tab Optimization.
-
In the Compression section, clear the checkbox Gzip compression.
-
Click Apply. While the settings are being applied, the resource will have the
PROCESSINGstatus. Applying other settings is not available during this time. The settings will be applied once the resource status changes toACTIVE.
Brotli compression algorithm
Brotli is a compression algorithm that provides a higher compression ratio than Gzip — on average by 20%.
Brotli has limitations:
- works only over HTTPS;
- compatible only with modern browsers;
- processes only certain file types.
List of file types processed by Brotli:
application/javascript;application/json;application/vnd.apple.mpegurl;application/vnd.ms-fontobject;application/x-font-opentype;application/x-font-truetype;application/x-font-ttf;application/x-javascript;application/xml;application/xml+rss;font/eot;font/opentype;font/otf;image/svg+xml;image/vnd.microsoft.icon;image/x-icon;text/compressible;text/css;text/javascript;text/xml.
Enable Brotli compression algorithm
-
In the control panel, in the top menu, click Products and select CDN.
-
In the CDN resources section, open the resource page → tab Optimization.
-
Make sure that in the Delivery optimization type section, the selected option is Static.
-
In the Compression section, select the checkbox Brotli compression.
-
Click Apply. While the settings are being applied, the resource will have the
PROCESSINGstatus. Applying other settings is not available during this time. The settings will be applied once the resource status changes toACTIVE.
Disable Brotli compression algorithm
-
In the control panel, in the top menu, click Products and select CDN.
-
In the CDN resources section, open the resource page → tab Optimization.
-
In the Compression section, clear the checkbox Brotli compression.
-
Click Apply. While the settings are being applied, the resource will have the
PROCESSINGstatus. Applying other settings is not available during this time. The settings will be applied once the resource status changes toACTIVE.
Check compression algorithm performance
-
Go to your website that is delivered via CDN.
-
Open developer tools → tab Network.
-
In the Name section, click the row with the CSS or JS file.
-
On the Headers tab, in the Response headers section, find the header Content-Encoding:
- if the header value is
gzip, it uses the Gzip compression algorithm; - if the header value is
br, it uses the Brotli compression algorithm; - if the header is missing, compression is not applied. This may happen because compression algorithms are disabled in the CDN resource settings or only Brotli compression is enabled, which is not supported by the user's browser.
- if the header value is
-
If there is no Content-Encoding header, check in the CDN resource settings that the Gzip compression algorithm is enabled and, if necessary, Brotli.