How to gzip svg files in ASP.NET

My previous post showed how to gzip svg files served by the Sitecore media library. This is fine if all svg files reside in the media library but this is typical not the case.

In this post I will show how to gzip compress any svg files served by your ASP.NET solution. As I explained in my previous post the issue that I am attempting to solve is that IIS will not by default gzip svg files without a lot of configuration changes on server level.

The solution here is extremely simple and pragmatic. Simply implement a HttpModule and set the Response.Filter stream to a GZipStream.

GZip svg files

Then add the httpmodule to configuration

That is it. I hope this helps someone out there in their own personal fight with Google PageSpeed.



Avatar photo

Anders Laub Christoffersen

Anders has been working with Sitecore for over a decade and has in this time been the lead developer and architect on several large scale enterprise solutions all around the world. Anders was appointed the title of Sitecore Technical MVP in 2014 and has been re-appointed the title every year since then.

5 thoughts on “How to gzip svg files in ASP.NET

  1. I tried to implement gzip for font in so many ways but nothing worked. You solution worked like magic. Hats of man…genius better solution with full control.

  2. Thank you for sharing.. Works like a charm

  3. Sir, you are my hero tonight… I was already screaming bloody murder

    Thank you

Comments are closed.