Install and config Brotli Compression with Apache

Today’s world is growing very fast and everyone is in a hurry! According to a Google study, 40% of people abandon a website that takes more than 3 seconds to load and a 1-second delay in page response can result in a 7% reduction in conversions. Yes, every second matters! hence Brotli comes into effect to speed up your website.

Just like Gzip, Brotli is also a generic-purpose compression algorithm developed by Google. It compresses data using a combination of modern technologies and algorithms. It is similar in speed to deflate but provides higher compression. Brotli compression is supported by all the major browsers like Chrome, Firefox, Safari, Edge.

In this Article we are going to configure Brotli Compressor Mechanism with Apache Web Server.

See on Youtube:

Prerequisites

  1. Need sudo  privileged account.
  2. Assumed that you have Apache webserver running with a Virtual host which serving web content.

Well, at this point we understand that Brotli can help you to speed up your heavy website, and save your bandwidth also. And eventually, it helps optimization on SEO ranking in the competition market.

We assume that you have an existing web server with Apache in order to do the experiment, and if you are in a production environment then I strongly recommend to make a backup your files before that. You can also check out this video how to setup Apache Vhost above here.

Go ahead and open terminal type :

sudo apt install brotli 

So, after install Brotli, enable the module in Apache.

sudo a2enmod brotli 

Now You need to restart Apache2 in order to make module effective.

sudo systemctl restart apache2 

Now, open up Apache Vhost config file. go ahead and type nano /etc/apache2/site-available/<your config file>.

Inside your config file place cursor after directory tag and put an If Module.

<VirtualHost *:80>
    ServerName myapp1.com

    ServerAdmin [email protected]
    DocumentRoot /var/www/html/wordpress/

    <Directory /var/www/html/wordpress>
        Options Indexes MultiViews
        AllowOverride All
        Require all granted
    </Directory>
/////////////////////////////// Add this config to your Vhost file ////////////////////////////
    <IfModule mod_brotli.c>
        AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
    </IfModule>
///////////////////////////////////////////////////////////////////////////////////////////////

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

 

Inside If Module add output filter type Brotli Compress, and then put your file type you want to compress. So, here is put html, css, Js etc.

After that save the configuration and exit. And again, restart the Apache service in order to make effect in your website.

sudo systemctl restart apache2 

Now open up the browser and load the page in another tab, it will be bit faster than previous. You could check whether your Brotli Compressor work or not, using Curl command. So, open a local terminal and type the following command.

curl -I -H 'Accept-Encoding: br' http://myapp1.com 

You can see the output that content encoding Brotli is working fine for me.

HTTP/1.1 200 OK
Date: Mon, 09 Aug 2021 06:50:56 GMT
Server: Apache/2.4.41 (Ubuntu)
Link: <http://myapp1.com/index.php?rest_route=/>; rel="https://api.w.org/"
Vary: Accept-Encoding
Content-Encoding: br
Content-Length: 1
Content-Type: text/html; charset=UTF-8

So, guys hope this article helpful to you, Thank you.

The following two tabs change content below.

Subroto Mondal

Chief Coordinator HR&CR
I like Programming and New Technologies. And work with Linux.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.