GICT knowledge base
What is Brotli Compression? Why Brotli is better than Gzip?
Published
What is Brotli Compression? Why Brotli is better than Gzip?
Brotli is a type of compression developed by Jyrki Alakuijala and Zoltán Szabadka. It is an Open Source technique and based on the modern LZ77 algorithm, 2nd order and Huffman coding context modeling. This will boost the website performance much more in all browsers. Brotli was released on 2015 September by Google software engineers by enhancing lossless data compression with the use of HTTP compression.
The Brotli compression technique uses a pre-defined 120Kb dictionary in addition with Sliding Window dictionary. Brotli compression ensures better space utilization and faster page loads with smaller compressed size and it is far better than gzip compression mechanism. While Gzip compression uses a fixed window of 32KB but in Brotli uses a sliding window of 1KB to 16MB. Let’s discuss some of the benefits of Brotli compression technique:
1) A quicker website access
2) Improved security
3) Increased trust from Google leading to improved rankings.
Unlike Zopfli compression which is Deflate-compatible, Brotli compression is a new type of data format which offers significant compression which will attain 20-26% better than Zopfli compression. Apache now adds support to 2.4 version, but it does require Brotli library and some compile options. Let’s discuss about the steps to set up Brotli compression in Apache 2.4:
1) Make sure you have already installed “wget, perl, gcc, pcre-devel, cmake.x86_64” packages. And then execute below commands to enable Brotli compression on Apache webserver.
# cd ~
# mkdir sources && cd sources
# git clone https://github.com/google/brotli.git
# cd brotli/
# git checkout v0.6
# mkdir out && cd out
# ./configure-cmake
# make
# make test
# make install
2) Now we need to install Latest version Apache 2.4.26 or higher. You can easily install by executing below commands.
# wget https://www.apache.org/dist/httpd/httpd-2.4.26.tar.gz.asc
# tar -zxvf httpd-2.4.26.tar.gz
# cd httpd-2.4.26
# ./configure –with-pcre=/usr/bin/pcre-config –enable-ssl –enable-so –enable-brotli –with-brotli=/usr/local/brotli
# make
# make install
3) Next, we need to enable the compression on Apache configuration file. This is similar to Gzip compression configuration. Add below codes to “brotli.conf” file and Include the location at Apache configuration file.
LoadModule brotli_module modules/mod_brotli.so
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript application/json application/x-font-ttf application/vnd.ms-fontobject image/x-icon
BrotliFilterNote Input brotli_input_info
BrotliFilterNote Output brotli_output_info
BrotliFilterNote Ratio brotli_ratio_info
LogFormat ‘”%r” %{brotli_output_info}n/%{brotli_input_info}n (%{brotli_ratio_info}n%%)’ brotli
CustomLog “|${APACHE_ROOT}/bin/rotatelogs ${APACHE_LOG_DIR}/brotli_log.%Y%m%d 86400” brotli
#Don’t compress content which is already compressed
SetEnvIfNoCase Request_URI \
\.(gif|jpe?g|png|swf|woff|woff2) no-brotli dont-vary
# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
Then restart Apache service and you can see the Content-Encoding as “br” on your browser text resources.
If you need any further help, please reach our support department.
Related guides
How to Restrict an SSH Key to One Command
Restrict an SSH key to one command with authorized_keys options. Protect the command and check that unwanted shell and forwarding access are denied.
Linux and CommandsSelf-Hosted Video Processing With FFmpeg: A Practical Guide
Learn how to self-host video processing on a VPS using FFmpeg, with practical commands for conversion, compression, thumbnails, and automated workflows.
Linux and CommandsHow to use nohup: Commands in Linux That Survive Terminal Closes
Keep commands running after you close the terminal. nohup examples with wget, Python, rsync, and Docker on any VPS.
Linux and CommandsHow to Fix “Too Many Open Files” Error on Linux Servers
Learn how to fix the "Too Many Open Files" error on Linux servers by understanding file descriptors, adjusting limits, and diagnosing leaks effectively.
