【问题标题】:Resource interpreted as Font but transferred with MIME type application/x-font-woff资源解释为字体但使用 MIME 类型 application/x-font-woff 传输
【发布时间】:2013-05-18 06:49:00
【问题描述】:

我按照 qooxdoo 文档中的Web Fonts tutorial 将网络字体添加到 Font.js ,但我注意到 Chrome 的开发者控制台中有一个警告:

我的代码如下:

/* ************************************************************************
  #asset(myApp/fonts/*)
************************************************************************ */
qx.Theme.define("myApp.theme.Font",
{
  extend : qx.theme.simple.Font,

  fonts :
  {
    "silkscreen" :
    {
        size: 8,
        lineHeight: 1,
        family: [ "silkscreen", "Tahoma" ],
        sources:
        [
            {
                family: "Silkscreen",
                source:
                [
                    "myApp/fonts/slkscr-webfont.eot",
                    "myApp/fonts/slkscr-webfont.ttf",
                    "myApp/fonts/slkscr-webfont.woff",
                    "myApp/fonts/slkscr-webfont.svg#silkscreen"
                ]
            }
        ]
    }
  }
});

如何解决浏览器警告?

【问题讨论】:

    标签: qooxdoo


    【解决方案1】:

    根据W3C spec,正确的MIME 类型是application/font-woff,因此您需要配置您的网络服务器以在提供.woff 文件时使用它。

    【讨论】:

    • 它有效。在我的Apache服务器配置的httpd.conf中添加AddType application/font-woff .woff行(然后重新启动服务器)后,警告消失了。
    • 试过这个解决方案,问题依旧。这是在使用 EasyPHP 的开发环境中。
    • 更新:我向 Apache 基金会提交了一份错误报告。希望他们会在未来的版本中更新默认值。
    • 以下规则对我有用: AddType application/vnd.ms-fontobject .eot AddType font/ttf .ttf AddType font/otf .otf AddType application/x-font-woff .woff AddType application/字体-woff .woff
    • @iamdash,感谢您发布与其他字体类型相关的 conf。但是 .woff 的第二个指令不是简单地覆盖第一个吗? IOW,我认为您只是将 .woff 设置为 application/font-woff 并且永远不会应用倒数第二个指令(“AddType application/x-font-woff .woff”)。我认为特别是对于 .woff,Daniel Wagner 的回答仍然正确。 PS 我曾经看到这个控制台错误,但在最新的 Chrome(29.0.1547.65,在 OSX 上)我的 .woff 字体类型为 application/x-font-woff 并且不会触发控制台错误。也许Chrome现在正在抑制错误? /$.02
    【解决方案2】:

    如果您使用的是 IIS 网络服务器,请尝试一下:

    <system.webServer>
      <staticContent>
        <remove fileExtension=".woff" /> 
        <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      </staticContent>
    </system.webServer>
    

    【讨论】:

    • 是的,如果 Web 服务器在 IIS 中,这就是接受答案的含义。不需要# 标记,对吧?
    猜你喜欢
    • 2015-08-22
    • 2013-08-18
    • 2012-04-26
    • 2017-05-12
    • 2015-11-16
    • 2017-03-19
    • 1970-01-01
    • 2017-01-30
    相关资源
    最近更新 更多