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.
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.
To enable Brotli using the command provided below:
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:
An example virtual host may look like this:
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).
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:
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.
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.