One way to speed up website access is to cache data. Another effective way is to enable data compression. Gzip is a common compression function. Today, we will introduce another compression method: the brotli module developed by Google. Brotli was originally released in 2015 for offline compression of web fonts. Google software engineers released an enhanced version of Brotli that includes general lossless data compression in September 2015.
The encoder has been partially rewritten to increase the compression ratio, both the encoder and decoder have been improved in speed, and the streaming API has been improved to add more compression quality levels. The new version also showcases cross-platform performance improvements, as well as reduced memory required for decoding.
For the difference between brotli and Gzip, please read: Gzip vs Brotli compression algorithm, which is better?
Install Brotli on Nginx and enable
nginx currently does not support the Brotli algorithm, and requires the use of third-party modules, such
ngx_brotlithe module and its dependencies:
$ git clone https://github.com/google/ngx_brotli $ cd ngx_brotli $ git submodule update --init
ngx_brotliAdd the module when compiling Nginx :
$ cd /path/to/nginx_source/ $ ./configure --add-module=/path/to/ngx_brotli $ make && make install
httpAdd the following directives under the block of the Nginx configuration file :
When enabled will check
brfor pre-compressed files with extensions. If it is
always, the compressed file is always used, regardless of browser support.
Whether to enable compressing files in on-the-fly mode, after enabling, the files will be compressed and returned in response.
Specifies which content-encoding types are compressed.
text/htmlContent is always compressed.
Set the number and size of buffers. The size defaults to the size of a memory page, ie,
Sets the compression quality level. The value range is 0 to 11.
Set the window size.
Sets the minimum response size that needs to be compressed.