Author |
|
Steffen Moderator
Joined: 15 Oct 2005 Posts: 3092 Location: Hilversum, NL, EU
|
Posted: Wed 26 Apr '17 13:48 Post subject: Mod_brotli compression insight |
|
|
With 2.4.26 there is the new module mod_brotli.
Note: Brotli command line tool see www.apachelounge.com/viewtopic.php?p=35899
Brotli is a new compression algorithm that was developed by Google in order to help further reduce the size of files. This means less bandwidth is used to transfer files that take advantage of Brotli compression and visitors accessing these files receive them faster. Many studies such as Google’s Compression Algorithm Study have shown impressive compression results using Brotli. A 20-26% higher compression ratio has been seen when comparing Brotli to Zopfli (another modern compression algorithm). see also https://en.wikipedia.org/wiki/Brotli
A few highlights and important facts about Brotli you should be aware of include:
◾Brotli offers a comparable compression ratio offered by the best compression methods and uses less CPU. Additionally, it is considerably better than Gzip.
◾Both the server and browser must be Brotli compatible to take advantage of this compression method (more on browser and web server support below).
◾Browsers will not accept Brotli encoding over HTTP connections, only HTTPS.
Browser support:
Chrome since version 50,
Android Browser version 50,
Chrome for Android since version 50,
Firefox since version 44,
Firefox for Android since version 46,
Opera since version 38.
Apache configuration:
https://httpd.apache.org/docs/trunk/mod/mod_brotli.html
Apachelounge is running it with;
LoadModule brotli_module modules/mod_brotli.so
SetOutputFilter BROTLI_COMPRESS;DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpg|png|zip|pdf|rar|css)$ no-gzip no-brotli dont-vary
Test:
https://tools.keycdn.com/brotli-test
Last edited by Steffen on Wed 04 Oct '17 16:37; edited 2 times in total |
|
Back to top |
|
Steffen Moderator
Joined: 15 Oct 2005 Posts: 3092 Location: Hilversum, NL, EU
|
Posted: Thu 27 Apr '17 12:07 Post subject: |
|
|
To test/compare with Curl, add the header with :
Brotli: -H "Accept-Encoding:br"
Deflate: -H "Accept-Encoding:gzip" |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1266 Location: Amsterdam, NL, EU
|
Posted: Fri 28 Apr '17 11:53 Post subject: |
|
|
Is there an easy way to test what the compression level is? I have got mod_brotli running now on 2 Apache 2.4.25 instances on my dev server (VC11 x64 and VC14 x64) and on my laptop with Apache 2.4.25 VC9 x86. I would like two know the difference. |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1266 Location: Amsterdam, NL, EU
|
Posted: Fri 28 Apr '17 19:49 Post subject: |
|
|
OK, I saw the difference in the Apache logs and in the Curl output. Mod_brotli compressed a 179K phpinfo() to 34597 bytes, somewhat smaller than the 38030 bytes with gzip/deflate.
Code: | D:\>curl -k -O https://example.com/phpinfo.php
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 179k 0 179k 0 0 719k 0 --:--:-- --:--:-- --:--:-- 719k
D:\>curl -k -H "Accept-Encoding:gzip" -O https://example.com/phpinfo.php
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 38030 100 38030 0 0 198k 0 --:--:-- --:--:-- --:--:-- 198k
D:\>curl -k -H "Accept-Encoding:br" -O https://example.com/phpinfo.php
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 34597 100 34597 0 0 167k 0 --:--:-- --:--:-- --:--:-- 167k
|
|
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1266 Location: Amsterdam, NL, EU
|
Posted: Fri 05 May '17 13:36 Post subject: |
|
|
I have put mod_brotli in production now (with Apache 2.4.25 VC9 x86). I did not exclude files by extension, like AL is doing. This caused problems ith Drupal 7:
Code: | SetOutputFilter BROTLI_COMPRESS;DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpg|png|zip|pdf|rar|css)$ no-gzip no-brotli dont-vary
|
Drupal 7 compresses the css and js files to *.css.gz and *.js.gz and sends those to the client in stead of the requested *.css and *.js. In the standard Drupal 7 .htaccess it prevents that the server deflates or gzips those files for the second time.
However Drupal knows nothing of brotli compression with the result that the already gzipped *.css and *.js files became compressed twice and were unreadable by the browser.
When I saw the Drupal tricks, I took the safe road and made only certain file types subject to mod_brotli. For this I also had to enable mod_filter.so. Part of my httpd.conf now:
Code: | LoadModule brotli_module modules/mod_brotli.so
AddOutputFilterByType BROTLI_COMPRESS;DEFLATE text/html text/plain text/xml
|
|
|
Back to top |
|
admin Site Admin
Joined: 15 Oct 2005 Posts: 692
|
Posted: Mon 19 Jun '17 13:45 Post subject: |
|
|
Brotli command line tool added to the additional download page. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1266 Location: Amsterdam, NL, EU
|
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 05 Jul '17 13:25 Post subject: |
|
|
Ya it is BROTLI not BROTLI_COMPRESS;
Thanks for the hint! |
|
Back to top |
|