Site iconJava PDF Blog

How to Enable SVG Gzip Compression on Apache and NGINX

html5

Gzip compression is a widely supported method of reducing the size of the content sent from a web server in order to improve the load time. Effectively all browsers support gzip compression (IE6+, Firefox 2+, Chrome 1+, etc).

In our experience as the creators of a PDF to SVG converter, our research shows that SVG files, in particular, can be highly compressible. We find that some files reduce by as much as 80-90% when compressed!

The standard way to enable compression is on the web server. Tutorials that show how to enable gzip compression do not often include SVG files, so if you follow another guide you should make sure to apply compression to the image/svg+xml MIME-type.

Enabling Gzip on Apache

Add the following to the .htaccess file:

AddOutputFilterByType DEFLATE image/svg+xml

Read the official Apache documentation on configuring gzip compression

Enabling Gzip on NGINX

Add the following to the server configuration:

server {
    gzip on;
    gzip_types      image/svg+xml;
    gzip_proxied    no-cache no-store private expired auth;
}

Read the official NGINX documentation on configuring gzip compression

Enabling Gzip on IIS

Read the official IIS documentation on configuring gzip compression

If you would like to do more with gzip compression, we recommend reading the official documentation (links above) to ensure you get the most accurate information.