can't get iis7 to gzip font-face font files
Asked Answered
I

5

24

im on a shared webhost and i only have access to the web.config file for iis7.5. javascript files and css files are gzipped, so that works, but i think that works by default because static compression is enabled in iis7.5. however, i cannot get font files to get gzipped, they are the same size when sent and the response headers dont have content-encoding: gzip. thank you for any help.

this is the web.config file:

<configuration>
<system.webServer>
    <directoryBrowse enabled="false" />
<staticContent>
    <mimeMap fileExtension=".otf" mimeType="font/opentype" />
</staticContent>
<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="font/open-type" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="text/css" enabled="true" />
    <add mimeType="text/html" enabled="true" />
    <add mimeType="*/*" enabled="false" />
        </dynamicTypes>
    <staticTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="font/opentype" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />
        </staticTypes>
</httpCompression>
    <urlCompression dynamicCompressionBeforeCache="true" doDynamicCompression="true" doStaticCompression="true" />
    <defaultDocument>
        <files>
            <clear />
            <add value="Default.htm" />
            <add value="Default.asp" />
            <add value="index.htm" />
            <add value="index.html" />
            <add value="iisstart.htm" />
            <add value="default.aspx" />
            <add value="index.php" />
        </files>
    </defaultDocument>

</system.webServer>
</configuration>
Ivanivana answered 19/1, 2013 at 1:49 Comment(0)
A
48

By default IIS doesn't include those MIME Types in the httpCompression module. You need to modify your applicationHost.config file in: C:\Windows\System32\inetsrv\config.

This file will affect all your websites and must be opened with a 64-bit text editor in a 64-bit Windows. (Notepad2 64-bit, Notepad, do not use Notepad++)

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

            <!-- HERE -->
            <add mimeType="image/svg+xml" enabled="true" />
            <add mimeType="application/font-woff" enabled="true" />
            <add mimeType="application/x-font-ttf" enabled="true" />
            <add mimeType="application/octet-stream" enabled="true" />
            <!-- HERE -->

        </staticTypes>
        <dynamicTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />
            <add mimeType="*/*" enabled="false" />

            <!-- HERE -->
            <add mimeType="image/svg+xml" enabled="true" />
            <add mimeType="application/font-woff" enabled="true" />
            <add mimeType="application/x-font-ttf" enabled="true" />
            <add mimeType="application/octet-stream" enabled="true" />
            <!-- HERE -->

        </dynamicTypes>
</httpCompression>

These are my personal settings to compress SVG, WOFF, EOT and TTF files.

Then simply type iisreset in your command line to reload the config in IIS, or restart your computer.

UPDATE

Woff and Woff2 files are already compressed, so you don't need to do this. In fact, the client will lose performance if you gzip those.

Altamira answered 29/5, 2014 at 18:19 Comment(8)
Out of interest, why is a 64 bit editor required? I've never heard of this requirement before.Florida
I've followed this and checked over a dozen times. IIS still refuses to serve my .svg files gzipped. The only way I've had success is to set the mimetype of .svgs to "text/xml" but then they don't render properly in many browsers.Bis
BTW: Notepad++ now also comes in a 64-bit flavor.May
Here is a link to Notepad 2.May
@Bis Try changing the URL after you make the change, e.g.: /foo.svg?v=1, to avoid caching issues.Datura
Please remove the woff entries from the code examples then or people will blindly copy/paste without reading your update.Dulcinea
@dan-diplo 64-bit editors are needed to open some filepaths unless you modify them appropriately: serverfault.com/questions/315904/…Dumbwaiter
@uwe-keim unfortunately various Notepad++ plugins aren't available for the 64-bit version (at least last time I had checked)Dumbwaiter
C
8

The important thing to note is that modifying your applicationHost.config (in %windir%\system32\inetsrv\config) from the following setting:

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />

to:

<section name="httpCompression" overrideModeDefault="Allow" />

will enable configuration of the httpCompression tag under the system.webServer tag in your web.config.

Cule answered 16/3, 2015 at 17:46 Comment(1)
This doesn't work. You have to actually add the line <add mimeType="image/svg+xml" enabled="true" /> in the applicationHost.config. Setting it in the web.config has no effect, even if you change the settings in as suggested in this answer. (At least on IIS 8.5, Win8.1)Euromarket
B
5

The problem is that by default IIS doesn't include the mime types for the web fonts in the list of mime types that can be compressed. Javascript and css files are included which is why you are seeing them getting compressed.

Your httpCompression settings are probably not being used, those are locked by default and cannot be set in the web.config. Take a look at this page: http://support.microsoft.com/kb/969062. In the "More Information" section it says, "you can set MIME types for the web server level only."

The only way I could get this to work on my local server was to add the mime types in the httpCompression section of applicationHost.config (this requires admin access). Setting them in web.config had no affect.

Bissonnette answered 8/4, 2013 at 20:46 Comment(0)
F
4

If you cannot access the applicationhosts.config in all environments a more pragmatic approach is simply to implement a httpmodule for gzipping the svg files.

See this post for a code example: http://laubplusco.net/gzip-svg-files-asp-net/

Flank answered 3/9, 2014 at 12:54 Comment(0)
J
0

I was still having this issue despite having enabled static and dynamic compression via the IIS remote management console.

I finally managed to resolve it by changing the mime type of .tff files from application/octet-stream to font/ttf on IIS.

Josettejosey answered 20/7, 2019 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.