Installation Brotli on Ubuntu server

Last updated December 6th, 2023 00:15

Data compression is crucial for server speed. It helps reduce the size of transferred files between the server and the client, saving you time required to display the webpage. The web browser contacts the server, which compresses the data, sends the compressed data to the browser, where it is decompressed and displayed. Currently, two methods of data compression are commonly used: GZIP and Brotli. Today, let’s take a look at the installation process of Brotli on Ubuntu server.

In general, both methods can be used on the server, or they can coexist. The choice of compression method by the server depends on the browser’s request. If Brotli is not supported, the server will use GZIP. However, if the user’s browser supports Brotli (which is practically the case with all modern browsers), the server will prefer Brotli compression method.

Installation Brotli on Ubuntu server

Iinstallation Brotli on Ubuntu Server

Brotli is a modern compression algorithm used to reduce the size of data on the internet. It was developed by Google with the main goal of providing efficient data compression, which means reducing the file size for faster transmission over the network.

How does it work? Brotli utilizes a combination of different data reduction techniques to achieve a high compression ratio. One of the methods it uses is lossless compression, which means the file remains unchanged after compression. Brotli also employs dictionary compression, a method that replaces repetitive patterns in the data with shorter codes.

In simple terms, Brotli is like a magician that can pack a large amount of data into a smaller package. This improves the speed of data transmission over the internet and also saves server space. When a website or file uses Brotli compression, users can load the content faster and enjoy a better user experience.

Brotli is one of the most advanced compression algorithms available on the internet and is used in web browsers, web servers, and other applications. It makes the internet faster and more efficient for all users.

Let’s get started with the installation

Installing Brotli is relatively simple. In this guide, I will show you how to set it up on an Apache server. First, update the package list on your system:

				
					sudo apt update

				
			

Once the system has updated the package list, use the following command to install:

				
					sudo apt install brotli
				
			

Now the system will install Brotli, and we can proceed with further steps.

Apache Configuration

To enable Brotli using the command provided below:

				
					a2enmod brotli
				
			

Now you will need to modify the virtual host of your web hosting provider to add Brotli. This can be done using any text editor of your choice. In our case, we will use nano.

				
					sudo nano /etc/apache2/sites-available/muj-web.conf
				
			

Insight the command, simply replace “muj-web.conf” with the name of your website’s virtual host. In the nano editor, add the following lines:

				
					<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
    </IfModule>
				
			

An example virtual host may look like this:

				
					<VirtualHost 1.2.3.4:443>

    DocumentRoot /var/www/
    ServerName priklad.cz

    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

    CustomLog /var/log/apache2/priklad.cz.access.log common
    ErrorLog /var/log/apache2/priklad.cz.error.log

    <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
    </IfModule>

</VirtualHost> 
				
			

Once you have added the necessary lines, save the changes in the nano editor by using the CTRL+X key combination, then confirm the change by typing Y and pressing Enter.

Modify the .htaccess file if necessary

It is also recommended to add the directives to the .htaccess file on your website (please note that the .htaccess file must be active on your website).

				
					# Directives for Brotli compression
<IfModule mod_deflate.c>
    SetEnv no-gzip 1
</IfModule>

<IfModule mod_filter.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript
</IfModule>
				
			

Test if Brotli is active

If you have modified the virtual host and the .htaccess file, you can test the active Brotli compression using the following command (the -i flag will display only the header of the HTTP response for the specified website):

				
					curl -I -H 'Accept-Encoding: br' https://vas-web.cz
				
			

You should receive a response similar to this:

				
					HTTP/2 200 
date: Thu, 23 Apr 2020 12:45:55 GMT
server: Apache/2.4.38 (Ubuntu)
strict-transport-security: max-age=15552000; includeSubDomains
last-modified: Wed, 08 Apr 2020 14:53:30 GMT
etag: "15e8-5a2c8a9d7bf77-br"
accept-ranges: bytes
vary: Accept-Encoding
content-encoding: br
content-length: 1539
content-type: text/html
				
			

If the following line is included in the header response, Brotli compression is active:

				
					content-encoding: br
				
			

Installation of Brotli on Ubuntu server – Conclusion

As you can see, installing Brotli is not particularly difficult. However, despite this fact, I recommend taking a backup of your server data beforehand or, if possible, creating a server snapshot.

The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.

Byl pro Vás tento článek užitečný?

Klikni na počet hvězd pro hlasování.

Průměrné hodnocení. 0 / 5. Počet hlasování: 0

Zatím nehodnoceno! Buďte první

Jak užitečný vidíte tento článek.

Sledujte mě na sociálních médiích.

Je mi líto, že pro Vás nebyl článek užitečný.

Jak mohu vylepšit článek?

Řekněte mi, jak jej mohu zlepšit.

newsletter

Subscribe to the Newsletter

Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.

Odebírat
Upozornit na
guest
0 Komentáře/ů
Vložené zpětné vazby.
Zobrazit všechny komentáře.

Pokud mi chcete napsat rychlou zprávu, využije, prosím, níže uvedený
kontaktní formulář. Děkuji.

Další Kontaktní údaje