无法将iis7转换为gzip字体字体文件 [英] can't get iis7 to gzip font-face font files

查看:81
本文介绍了无法将iis7转换为gzip字体字体文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在共享的Web主机上,我只能访问iis7.5的web.config文件. 将javascript文件和css文件压缩后,可以使用,但是我认为默认情况下可以使用,因为在iis7.5中启用了静态压缩.但是,我无法获得要压缩的字体文件,发送时它们的大小相同,并且响应标头没有内容编码:gzip. 谢谢您的帮助.

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.

这是web.config文件:

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>

推荐答案

默认情况下,IIS在httpCompression模块中不包含那些MIME类型. 您需要在以下位置修改applicationHost.config文件: C:\ Windows \ System32 \ inetsrv \ config .

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.

此文件将影响您的所有网站,并且必须在64位Windows中使用64位文本编辑器打开. (Notepad2 64位,记事本,请勿使用Notepad ++ )

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>

这些是我的个人设置,用于压缩 SVG WOFF EOT TTF 文件.

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

然后只需在命令行中键入 iisreset 即可在IIS中重新加载配置,或重新启动计算机.

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

更新

Woff Woff2 文件已经被压缩,因此您不需要这样做.实际上,如果对这些文件进行gzip压缩,客户端将失去性能.

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.

这篇关于无法将iis7转换为gzip字体字体文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆