For those who do not know, Brotli is a new compression method developed by Google. It is said to compress files ~20% smaller than gzip - means less bandwidth consumed and faster rendering on the client side. Mozilla has already added support for Brotli in Firefox 44, and Chrome is gradually turning the knob on as well.
Starting with H2O version 2.0.0-beta1, when the
file.send-compresseddirective is set to
ON, the server sends a file with
.gzsuffix instead of file being requested should such file exist. For example, if
index.htmlis requested with a
Accept-Encoding: brrequest header, and if a file named
index.html.brexists, the server sends the contents of
index.hmtl.bras the response with the
Content-Encoding: brresponse header being set. In case the client is capable of decompressing both algorithms both algorithms and if both of
.gzfiles exist, the
.brfile is selected as the response.
# send pre-compressed files (.br or .gz) file.send-compressed: ON
The other directive:
compresscontrols on-the-fly compression. When turned on, it compresses the response as it is being sent to the client, using either brotli or gzip depending on the configuration and browser support. This can be used for compressing output from PHP and other dynamically-generated content.
# perform on-the-fly compression (brotli or gzip) compress: [ brotli, gzip ]Server administrators may also be interested in fine-tuning the compression quality of the compression methods. The following configuration sets the compression quality of brotli to 4 and gzip to 6, a suggested setting by Understanding Brotli's Potential - The Akamai Blog. The compression speed becomes about half of the default (1 for both gzip and brotli), but the size of the content after compression is expected to become ~15% smaller for both methods.
# perform more effective (but CPU-intensive) compression compress: brotli: 4 gzip: 6
In my upcoming blogposts I will cover other changes in the 2.0 release of H2O. Stay tuned!