Evgenyt
Evgenyt

Reputation: 10731

How do I make IIS compress .svg files?

I'm trying to acomplish this in web.config:

<staticContent>
  <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
<httpCompression>
    <staticTypes>
        <add mimeType="image/svg+xml" enabled="true"/>
    </staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>

But Content-Encoding: gzip never appears in response headers. Though, compression works good for other types like CSS.

Upvotes: 11

Views: 14477

Answers (5)

Mike
Mike

Reputation: 7701

In my case, image/svg+xml was already listed as a mime type under <staticTypes> but it still wasn't working. On a whim I also added the mime type to <dynamicTypes> and that solved the problem.

Upvotes: 1

Hauke S
Hauke S

Reputation: 555

@Dominique Alexandre points to a solution that shows how you can edit the applicationHost.config file, which works just fine.

I just wanted to add how you can do this using the IIS Manager GUI.

Go to IIS Manager > YOUR_SERVER > Under Management section > Configuration Editor > Expand the system.webServer > httpCompression > dynamicTypes

And then add the mime types you want to be compressed additionally.

Upvotes: 5

Evgenyt
Evgenyt

Reputation: 10731

Not relevant, see Dominique Alexandre solution

OK, no one has answer. So I'll post here my temporary workaround.

I changed the mime type to text/xml, so it gets GZipped by IIS:

<mimeMap fileExtension=".svg" mimeType="text/xml" />

Upvotes: -2

Sprintstar
Sprintstar

Reputation: 8169

You need to turn it on for SVGs in IIS as a lower level. This post has the answer: https://stackoverflow.com/a/23940235/15233

Upvotes: 3

anders laub
anders laub

Reputation: 104

Changing the mime-type is really not nice.

See this post instead on how to implement a custom httpmodule which does the gzipping for you in a few lines of code.

http://laubplusco.net/gzip-svg-files-asp-net/

Upvotes: 0

Related Questions