#1 Install Brotil Module precompiled ubuntu & debian
sudo apt-get install brotli nginx nginx-module-brotli
#1.1 Add Repository if not yet added by default
sudo apt-add-repository -y ppa:hda-me/nginx-stable sudo apt-get update
check nginx version stable or mainline and current version.
and repeat 1st step,
#1.3 installing brotle from source github compiling on server
check how to add dynamic module in nginx.
#2 Load module in nginx .conf top
nano /etc/nginx/nginx.conf load_module modules/ngx_http_brotli_filter_module.so; load_module modules/ngx_http_brotli_static_module.so;
#3 Replace Gzip conf with Brotil bottom of nginx.conf
#brotli brotli on; brotli_comp_level 5; brotli_static on; brotli_types text/xml image/svg+xml application/x-font-ttf image/vnd.microsoft.icon application/x-font-opentype application/json font/eot application/vnd.ms-fontobject application/javascript font/otf application/xml application/xhtml+xml text/javascript application/x-javascript text/plain application/x-font-truetype application/xml+rss image/x-icon font/opentype text/css image/x-win-bitmap;
compression level 0-11.
you may use html separate compression level
#3.1 Use along with Gzip
You can place brotli compression. below the GZIP. browsers automatically choose between them based on supported compression.
#4 Restart nginx and verify the compression Accept-encoding
systemctl restart nginx
HTTP/2.0 200 OK server: nginx content-type: text/html; charset=UTF-8 vary: Accept-Encoding, content-encoding: br
Content length with gzip
content length with brotil
- Compile & install Nginx from source with brotli support
& Remove existing
Starts or restarts Nginx
#1 Installing Brotil in Apache ubuntu debian
sudo apt install brotli && sudo a2enmod brotli
#2 Configuring brotil in apache
you can edit conf directory in conf directory or module directory.
Adding to host for specific directory website.
<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>
3. systemctl restart apache2
verifying terminal or online curl tool or chrome de tools
curl -I -H 'Accept-Encoding: br' https://raazkumar.com curl -I https://raazkumar.com
curl -I -H 'Accept-Encoding: gzip' https://raazkumar.com
content-encoding: br
GZIP (Deflate) vs Bortil
GZIP: LZ77 +Huffman coding = Deflate algorithm.
General Rule: brotil compress better than gzip.
Why we use brotil instead of gzip?
faster than gzip, efficient than gzip.
it uses a dictionary of common keywords and phrases on both client and server side and thus gives a better compression ratio.
Js 14%, html 21%, Css 17% smaller than gzip as per recent study.
Images: may already compressed.
Compression level 1-11 (11 means high compression) 1MB file 1KB means 90% compression.
pagespeed improment maybe upto 30%-50% for static files.
gzip compression level by default 5 you may increase upto 11 for static files.
the downside is compression time. do test and deploy.
improve Page load speed 3 seconds to 2 seconds (30% smaller page size than gzip)
Troubleshooting
The following packages have unmet dependencies:
nginx-module-brotli : Depends: nginx (= 1.17.3-2-ppa7~bionic) (compiled with 1.17 )
E: Unable to correct problems, you have held broken packages.
root@instance-1:~# nginx -V
nginx version: nginx/1.19.1
built by gcc 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1) (Bionic )
we need to compile with installed nginx. or remove old nginx, install with brotil. dynamic module.
Brotil by google at github