logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> How-to's & Documentation & Tips View previous topic :: View next topic
Reply to topic   Topic: Mod_brotli compression insight
Author
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3094
Location: Hilversum, NL, EU

PostPosted: Wed 26 Apr '17 13:48    Post subject: Mod_brotli compression insight Reply with quote

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: 3094
Location: Hilversum, NL, EU

PostPosted: Thu 27 Apr '17 12:07    Post subject: Reply with quote

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

PostPosted: Fri 28 Apr '17 11:53    Post subject: Reply with quote

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

PostPosted: Fri 28 Apr '17 19:49    Post subject: Reply with quote

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

PostPosted: Fri 05 May '17 13:36    Post subject: Reply with quote

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

PostPosted: Mon 19 Jun '17 13:45    Post subject: Reply with quote

Brotli command line tool added to the additional download page.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7374
Location: Germany, Next to Hamburg

PostPosted: Mon 03 Jul '17 23:27    Post subject: Reply with quote

apachectl -M show that mod_brotli is loaded[1].

however I get an error with the syntax check

Quote:
AH00526: Syntax error on line 92 of /opt/apache2/conf/modules.conf:
Unknown filter provider BROTLI_COMPRESS


the config is very simple [2]

I did the build from github master clone with apxs [3[

Aapache version 2.4.26

[1] https://www.hastebin.com/musiholugi.swift
[2] https://www.hastebin.com/ebadiraxas.nginx
[3] https://www.hastebin.com/isikanacez.js
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1266
Location: Amsterdam, NL, EU

PostPosted: Tue 04 Jul '17 3:36    Post subject: Reply with quote

You are missing:
Code:
static void register_hooks(apr_pool_t *p)
{
    ap_register_output_filter("BROTLI_COMPRESS", compress_filter, NULL,
                              AP_FTYPE_CONTENT_SET);
}

http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/filters/mod_brotli.c?view=co

Or you should use "BROTLI" as filter:
https://github.com/kjdev/apache-mod-brotli/blob/master/mod_brotli.c#L47
https://github.com/kjdev/apache-mod-brotli/blob/master/mod_brotli.c#L720
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7374
Location: Germany, Next to Hamburg

PostPosted: Wed 05 Jul '17 13:25    Post subject: Reply with quote

Ya it is BROTLI not BROTLI_COMPRESS;

Thanks for the hint!
Back to top


Reply to topic   Topic: Mod_brotli compression insight View previous topic :: View next topic
Post new topic   Forum Index -> How-to's & Documentation & Tips