Dr Clèm's Blog

Tags: Apache HTTP Server

SVG with GZIP Compression in Apache HTTP Server

Friday Oct 20, 2017 16:45, last edition on Friday Oct 20, 2017 17:42

To save bandwidth with Apache HTTP Server, you can compress SVG files. On Ubuntu 16.04.3, Apache HTTP Server comes with version 2.4.27 which enable GZIP Compression by default.

# apache2 -v
Server version: Apache/2.4.27 (Ubuntu)
Server built: 2017-09-28T00:00:00
If not enable, you can do it with mod_deflate
# a2enmod deflate
For SVG Compression, edit the file /etc/apache2/mods-available/deflate.conf and add AddOutputFilterByType DEFLATE image/svg+xml between the IfModule. It should look like this
# cat /etc/apache2/mods-available/deflate.conf
<IfModule mod_deflate.c>
 <IfModule mod_filter.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
  AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE image/svg+xml
 </IfModule>
</IfModule>
Restart Apache HTTP Server
# systemctl restart apache2
Now, let us check if it is working with curl and its -I argument to query only the headers.
% curl -I https://clementfevrier.fr/images/CC-BY-SA_icon.svg
HTTP/1.1 200 OK
Date: Fri, 20 Oct 2017 14:23:11 GMT
Server: Apache/2.4.27 (Ubuntu)
Upgrade: h2
Connection: Upgrade
Last-Modified: Mon, 07 Oct 2013 03:09:42 GMT
ETag: "1bf8-4e81dfbbce980"
Accept-Ranges: bytes
Content-Length: 7160
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: sameorigin
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: strict-origin-when-cross-origin
Content-Type: image/svg+xml
and now with -H 'Accept-Encoding: gzip,deflate' to let know Apache HTTP Server that it can serve the file using compression
% curl -I -H 'Accept-Encoding: gzip,deflate' https://clementfevrier.fr/images/CC-BY-SA_icon.svg
HTTP/1.1 200 OK
Date: Fri, 20 Oct 2017 14:25:19 GMT Server: Apache/2.4.27 (Ubuntu) Upgrade: h2 Connection: Upgrade Last-Modified: Mon, 07 Oct 2013 03:09:42 GMT
ETag: "1bf8-4e81dfbbce980-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: sameorigin
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: strict-origin-when-cross-origin
Content-Length: 3077
Content-Type: image/svg+xml
In this case, the file is more than 2 times smaller (7160÷3077 ~ 2.326941826). Enjoy!

Mastodon Follow me Mastodon Share
Comments
There is no comment yet.
Post a comment

* required field.

Your comment

*

About you

*

*

Dr Clément Février

Bonjour, Je suis Clément Février, docteur en physique théorique de l’université de Grenoble Alpes, ingénieur Recherche et Développement dans le domaine de l’imagerie médicale et de la chirurgie mini-invasive chez Surgivisio et soutien du mouvement La France Insoumise.


Dites les velotaffeur, vous avez entendu parler d'un casque qui a un feu avant, un feu arrière et des clignotants sur les cotés / avant arrière ? (Enfin un simple bandeau led de chaque coté se gère hein)
Genre un truc pour que les voitures voient qu'on tourne à droite ou gauche sans qu'on ai besoin de tendre le bras ?

Parce que bon, j'ai testé ce soir, passer sur les marquages au sol + les rails du tramway avec un bras levé sous la pluie, niveau stabilité on repassera ^^'

J'arrive pas à trouver :/ et les solutions existantes de clignotants sont seulement pour l'arrière

Si le coeur vous en dit vous pouvez partager ;)

#velotaff #boostappréciés :)

The only thing that really matter is, at the end of the day, to choose the correct method automatically without conditional statement at runtime. I really wonder is a workaround is possible.
I already tried to add "std::tuple< d1*, d2 > b_tuple" to class b, using some forward declaration, but, of course, std::get< i >(b_tuple) cannot compile since it will be known at runtime only.

But I allow complete refactoring code, even the b and d1 & d2. Templates, new classes and sub classes and even are fine (I already put 100-lines define to add iterator to enum and another one to allow enum inheritance, and my coworkers begin to hate me ^^)
For example, method "create" can become a class, or class b can be construct using a macro to make somehow the base class aware of derived ones
BASE(b, ...) std::tuple< __VA_ARGS__ > g_ ## b; class b