WOFF字体应该作为什么mime类型?

我正在服务truetype (ttf)字体作为字体/truetype和opentype (otf)作为字体/opentype,但我找不到WOFF字体的正确格式。

我已经尝试了字体/woff,字体/webopen,和字体/webopentype,但Chrome仍然抱怨:

资源解释为字体,但使用MIME类型应用程序/字节流传输。

有人知道吗?


当前回答

对我来说,接下来就是在.htaccess文件中工作。

AddType font/ttf .ttf
AddType font/eot .eot
AddType font/otf .otf
AddType font/woff .woff
AddType font/woff2 .woff2   

其他回答

对我来说,接下来就是在.htaccess文件中工作。

AddType font/ttf .ttf
AddType font/eot .eot
AddType font/otf .otf
AddType font/woff .woff
AddType font/woff2 .woff2   

注:这个答案在当时是正确的,但在2017年RFC 8081发布时就过时了

没有字体的MIME类型!因此,font/xxx总是错误的。

它将是application/font-woff。

参见http://www.w3.org/TR/WOFF/#appendix-b (W3C候选推荐2011年8月04日)

和http://www.w3.org/2002/06/registering-mediatype.html

来自Mozilla css字体面注释

在Gecko中,web字体受到相同的域限制(字体文件必须与使用它们的页面在相同的域上),除非使用HTTP访问控制来放松这一限制。 注意:由于没有为TrueType、OpenType和WOFF字体定义MIME类型,因此不考虑指定文件的MIME类型。

来源:https://developer.mozilla.org/en/CSS/@font-face笔记

向.NET/IIS添加字体mime类型的参考

通过web . config

<system.webServer>
  <staticContent>
     <!-- remove first in case they are defined in IIS already, which would cause a runtime error -->
     <remove fileExtension=".woff" />
     <remove fileExtension=".woff2" />
     <mimeMap fileExtension=".woff" mimeType="font/woff" />
     <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
  </staticContent>
</system.webServer>

通过IIS管理器

更新自2017年6月22日Keith Shaw的评论:

截至2017年2月,RFC8081是建议标准。它为字体定义了一个顶级媒体类型,因此WOFF和WOFF2的标准媒体类型如下: 字体/ woff 字体/ woff2


2011年1月,Chromium宣布将同时承认

应用程序/ x-font-woff

作为《WOFF》的模版我知道这个改变现在是在Chrome测试版,如果还不稳定,它应该不会太远。