How do you turn on gzip compression for SVG files in IIS?
Asked Answered
F

1

10

I have created a web.config file that successfully turns on static compression for text and message resources. However, the obvious solution shown below does not seem to have any affect on .svg compression (validated that gzip content encoding not set in response header for .svg files, but is set for .html, css, etc. via chrome developer tools).

Here is my web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpCompression minFileSizeForComp="1024" MaxDiskSpaceUsage="500">
            <scheme name="gzip"/>
            <staticTypes>
              <add mimeType="text/*" enabled="true"/>
              <add mimeType="message/*" enabled="true"/>
              <add mimeType="application/javascript" enabled="true"/>
              <add mimeType="image/svg+xml" enabled="true"/>
              <add mimeType="application/json" enabled="true" />
              <add mimeType="*/*" enabled="false"/>
            </staticTypes>
        </httpCompression>
        <urlCompression doStaticCompression="true" doDynamicCompression="true"/>
        <staticContent>
          <remove fileExtension=".svg" />
          <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
          <remove fileExtension=".svgz" />
          <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" /> 
        </staticContent>
    </system.webServer>
</configuration>

The motivation for this question is to deliver compressed SVG fonts as recommended by Google Page Speed Insights. I've been testing this web.config on IIS 7.5/Windows 7 and IIS 8/Windows Server 2012.

Any ideas?

Fazio answered 5/12, 2013 at 22:44 Comment(3)
Did you find an answer for this? I'm using IIS 8 and it passes down the Content-Encoding: gzip for my SVG files, I cannot get SVGZ files to render to save my life. But according to Page Speed Insights my normal SVGs aren't gzipped even though I can see the header being applied in the web inspectorGrievous
@Grievous No solution yet.Fazio
Solution here: https://mcmap.net/q/543697/-can-39-t-get-iis7-to-gzip-font-face-font-filesSummit
I
4

IIS will not gzip too small files, and you can config the minium size. In IIS 7.5, the default value for the minFileSizeForComp is 2700.

Is your svg file too small? I config the httpCompression in IIS administrator GUI(not web.config) and it works well.

You can see the microsoft httpCompression config reference. sample code:

<httpCompression
      directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
   <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
   <dynamicTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/javascript" enabled="true" />
      <add mimeType="*/*" enabled="false" />
   </dynamicTypes>
   <staticTypes>
      <add mimeType="text/*" enabled="true" />
      <add mimeType="message/*" enabled="true" />
      <add mimeType="application/javascript" enabled="true" />
      <add mimeType="*/*" enabled="false" />
   </staticTypes>
</httpCompression>

You can also use compressed .svgz file instead of .svg file for saving CPU.

To config gzip content encoding for .svgz file, see: How to add Encoding for specific file types?

<system.webServer>
    <rewrite>
        <outboundRules>
            <rule name="Rewrite SVGZ header" preCondition="IsSVGZ" stopProcessing="true">
                <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" />
                <action type="Rewrite" value="gzip" />
            </rule>
            <preConditions>
                <preCondition name="IsSVGZ">
                    <add input="{PATH_INFO}" pattern="\.svgz$" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
    <staticContent>
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
    </staticContent>
</system.webServer>
Inbreathe answered 13/4, 2015 at 1:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.