What is Brotli compression?

Brotli compression, developed by Google and available on Github as open-source, is a new data compression algorithm specifically designed for web servers HTTP content encoding. It aims to provide a better compression ratio compared to the existing methods like Gzip compression, while maintaining a decent decompression speed. This compression technique is based on various lossless compression algithms (such as LZ77, Huffman coding and second‑order context modeling) and operates mainly by identifying redundant patterns within the data and replacing them with shorter representations, resulting in significantly smaller file sizes in most cases.

Brotli vs Gzip

Image taken from https://devblogs.microsoft.com/

Why should I enable Brotli compression for my website?

By providing a better compression ratio than Gzip, this means that with brotli compression you will provide faster download times for your website visitors and reduced bandwidth usage for your server, without significantly increasing the server load. This translates to improved user experience and potentially higher search engine (SEO) rankings due to faster web page load times. Google PageSpeed Insights is a good tool that can be used to measure the pagespeed and performance of your website.

How to enable Brotli compression on Nginx

First you may need to install ngx_brotli module if you are using the community version of Nginx:

This can be simplified a little by installing Brotli module by a package manager:

Then edit your Nginx vHost configuration file and add these lines:

Then restart Nginx for the changes to take effect:

How to enable Brotli compression on Apache

First make sure that Brotli module is enabled on Aapache:

Then edit your Apache configuration file and add these lines:

Then restart Apache for the changes to take effect:

Brotli doesn't support HTTP protocol, use HTTPS

If for some reasons this tool shows that Brotli is not supported on your website, make sure to use HTTPS.