OQwebdesign logo
  • Home
  • About
  • Tech Blog

Install Brotli in Apache on Debian 11

June 22, 2022
Share
Tweet
Share
0 Shares

Brotli is a new open-source compression format from google that improves on the performance of gzip in many cases, it only only works on an https connection. Enabling Brotli Compression means that your site files are shrinking and moving faster to visitor devices. Even someone with a slow internet connection or a mobile device with limited bandwidth can easily download your site.

Brotli has a general application so it can compress any type of file without destroying the data. However, it is not suitable for image files such as PNG, JPG, and GIF. These types of files are already compressed, and Brotli actually makes them bigger. You can try an image compression plugin instead.

Google’s Brotli is the new replacement for the old gzip and deflate compression. It is a revolutionary open source compression algorythm created by Google engineers. A Brotli study conducted by Gooogle confirmed that it can help to achieve up to 25% more compression ration for files than traditional gzip/deflate methods. It also uses less CPU, which helps to reduce server load significantly.

Prerequisites

Before installing getting started, you should already have install Ubuntu on your instance and have install Apache2.4 running as your web server with HTTPS. Apache has supported brotli since version 2.4.26 by way of the mod_brotli module. Check Apache version using this command on your terminal console.

apache2 -v

In Debian 11 you will get an output similar to the one below.

Server version: Apache/2.4.53 (Debian)
Server built: 2022-03-14T16:28:35

Update all available repositories on your system and install the Apache webserver using the apt command below.

sudo apt update && sudo apt upgrade -y

Installing Brotli binary

Run the following comnands

sudo apt-get install brotli -y

And your done.

Configure Apache

Apache ships with the brotli module and so it just needs enabling:

a2enmod brotli
service apache2 restart

Now we need to add the configuration so that Apache knows when to use brotli. You can put this configuration in either the VirtualHost file of a particular website or into the main configuration for all your sites:

Paste this configuration inside the file

<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css
    AddOutputFilterByType BROTLI_COMPRESS text/javascript application/x-javascript
    AddOutputFilterByType BROTLI_COMPRESS application/javascript application/json
    AddOutputFilterByType BROTLI_COMPRESS application/x-font-ttf
    AddOutputFilterByType BROTLI_COMPRESS application/vnd.ms-fontobject
    AddOutputFilterByType BROTLI_COMPRESS image/webp image/x-icon
 </IfModule>

a2enmod brotli
service apache2 restart
sudo a2dismod deflate

Check brotli is working

The best way to check if brotli is working is by using this simple website tool at GiftOfSpeed.com.

That should do it!

Popular Tech Posts

  • Easy way to setup a local HTTP Server on macOS
  • A NEW Modern Clearfix Hack With display: flow-root
  • Install Brotli in Apache on Debian 11
  • Use Let’s Encrypt certificates with Cockpit

Tag Cloud

Apache Web Server CSS Debian Install Brotli Laravel Nginx PHP Ubuntu Wordpress
white OQWebdesign logo

© Copyright 2007-2023 OQwebdesign. All rights reserved.

  • Home
  • About
  • Tech Blog