Brotli compression
Brotli is an open-source compression algorithm that provides better performance than Gzip compression. After you enable Brotli compression, CDN points of presence (POPs) compress resources with Brotli before returning them to clients. This reduces the size of transferred files, improves delivery efficiency, and reduces bandwidth consumption.
Background information
CDN POPs support two compression methods: Gzip compression and Brotli compression. This document describes how to configure Brotli compression. For more information about Gzip compression, see Gzip compression.
Gzip or Brotli compression applies only to files on the origin server that are between 1 KB and 10 MB in size.
Brotli compression supports the following file types: text/xml, text/plain, text/css, application/javascript, application/x-javascript, application/rss+xml, text/javascript, image/tiff, image/svg+xml, application/json, and application/xml.
Note: Enabling Brotli compression on already-compressed file types (such as PNG and JPG images, or MP4 videos) has no effect. For more information, see the usage notes below.
If the server response includes the
Content-Encoding: brresponse header, it indicates that the response content is Brotli-compressed.If a client request includes the
Accept-Encoding: brrequest header, it indicates that the client can accept Brotli-compressed content.If you enable both Brotli compression and Gzip compression, and the client request header
Accept-Encodingcontains bothbrandgzip, only Brotli compression takes effect.
Usage notes
When you use Brotli compression, take note of the following items (including interactions with Gzip compression, page optimization, and other features):
When CDN compresses static files, their MD5 values change. If your origin server uses an MD5 verification mechanism, disable both Gzip compression and Brotli compression.
If compression is enabled on the origin server and the server response includes the
Content-Encodingheader, the compression feature of CDN will not take effect.-
If you enable both HTML optimization and a compression feature (Gzip compression or Brotli compression), HTML optimization does not take effect. Alibaba Cloud CDN only compresses the files.
Brotli compression is supported only by some browsers. You can check browser compatibility based on your business requirements.
Common image file types (such as PNG, JPG, and JPEG) and video file types (such as MP4, AVI, and WMV) are already compressed. Enabling Gzip compression or Brotli compression does not reduce their size. We recommend that you disable compression for these files. To further reduce image file sizes, use the image processing feature. To further reduce video file sizes, use the audio and video transcoding feature. Both image processing and audio and video transcoding can reduce file quality.
Procedure
-
Log on to the CDN console.
-
In the left navigation pane, click Domain Names.
-
On the Domain Names page, find the target domain name and click Manage in the Actions column.
-
In the domain's navigation pane, click Optimization.
In the Brotli Compression section, turn on the Brotli Compression switch.
After you enable Brotli compression, you can compare the file received before and after enabling the feature. If the response header contains
Content-Encoding: br, the file has been compressed.