Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
775 views
in Technique[技术] by (71.8m points)

can't get iis7 to gzip font-face font files

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%inetpubempIIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%system32inetsrvgzip.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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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%inetpubempIIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%system32inetsrvgzip.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...