How to get Apache to compress SVG images

November 19, 2015

Today, I found out that Apache does not compress SVG images by default, even when mod_deflate is enabled. As SVG is completely text based, gzip can help to save bandwidth and increase page performance. To enable gzip compression for SVG files too, add the following line to your deflate.conf file:

AddOutputFilterByType DEFLATE image/svg+xml

In case you don’t have a deflate.conf file, you can enable it from httpd.conf with this snippet:

<IfModule mod_deflate.c>
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE image/svg+xml
    </IfModule>
</IfModule>