File compression algorithms
File compression is available if you select content delivery optimization type — 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 the quality and format of images (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 efficient 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 have 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 block, the selected option is Static.
-
In the Compression block, select the checkbox Gzip compression.
-
Click Apply. While the settings are being applied, the resource will be in the
PROCESSINGstatus. During this time, applying other settings is unavailable. The settings will be applied once the resource switches to the statusACTIVE.
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 block, clear the checkbox Gzip compression.
-
Click Apply. While the settings are being applied, the resource will be in the
PROCESSINGstatus. During this time, applying other settings is unavailable. The settings will be applied once the resource switches to the statusACTIVE.
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 block, the selected option is Static.
-
In the Compression block, select the checkbox Brotli compression.
-
Click Apply. While the settings are being applied, the resource will be in the
PROCESSINGstatus. During this time, applying other settings is unavailable. The settings will be applied once the resource switches to the statusACTIVE.
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 block, clear the checkbox Brotli compression.
-
Click Apply. While the settings are being applied, the resource will be in the
PROCESSINGstatus. During this time, applying other settings is unavailable. The settings will be applied once the resource switches to the statusACTIVE.
Check compression algorithm performance
-
Go to your website that is delivered via CDN.
-
Open developer tools → tab Network.
-
In the Name block, click the line with the CSS or JS file.
-
On the Headers tab, in the Response headers block, find the header Content-Encoding:
- if the header value is
gzip, the Gzip compression algorithm is applied; - if the header value is
br, the Brotli compression algorithm is applied; - 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.