字体 MIME 类型的正确 Apache AddType 指令
我使用 @font-face 来嵌入字体(感谢 Paul Irish)。在尝试修复 Chrome 关于 woff 字体错误 MIME 类型的警告时,我发现了大量相互矛盾的建议。
每个人似乎都同意 .eot 字体(适用于 IE 6-8?)应该使用
AddType application/vnd.ms-fontobject .eot
.ttf 字体(较旧的非 IE 浏览器?)我见过
AddType application/x-font-ttf .ttf
AddType application/octet-stream .ttf
AddType font/truetype .ttf
AddType font/ttf .ttf
对于 .woff 字体(新标准?)我已经 我知道
AddType application/font-wof .woff
AddType application/x-font-woff .woff
AddType application/x-woff .woff
woff 的 正确的 MIME 类型 将是 application/font-woff,但在标准正式发布之前,<一个href="http://code.google.com/p/chromium/issues/detail?id=70283#hc3">Chrome 可以识别 application/x-font-woff。
我意识到我在问这个问题时已经回答了一半,但问题确实是:关于字体应使用哪些 MIME 类型,是否有任何权威指导或进一步建议?
更新(如果它对其他人有任何帮助):由于似乎没有什么权威性,我决定在我的 .htaccess 中使用以下字体 MIME 类型(这至少让 Chrome 满意):
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-woff .woff
I’m using @font-face for embedded fonts (thanks Paul Irish). In trying to fix Chrome’s warning about wrong MIME type for woff fonts, I’ve discovered a mass of conflicting suggestions.
Everyone seems to agree that .eot fonts (for IE 6-8?) should be served using
AddType application/vnd.ms-fontobject .eot
For .ttf fonts (older non-IE browsers?) I’ve seen
AddType application/x-font-ttf .ttf
AddType application/octet-stream .ttf
AddType font/truetype .ttf
AddType font/ttf .ttf
And for .woff fonts (the new standard?) I’ve seen
AddType application/font-wof .woff
AddType application/x-font-woff .woff
AddType application/x-woff .woff
I understand the correct MIME type for woff will be application/font-woff, but until the standard is official, application/x-font-woff is understood by Chrome.
I realise I’ve half answered my question in asking it, but the question is really: is there any authoritative guidance or further advice about what MIME types should be used for fonts?
Update (in case it’s of any help to anyone else): since there seems to be nothing authoritative, I’ve settled on using the following font MIME types in my .htaccess (which at least keeps Chrome happy):
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-woff .woff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我意识到这个问题已经很老了,但是对于任何寻求快速复制/粘贴以将字体 MIME 类型添加到其 .htaccess 的人来说:
I realize that this question is old, but for anyone looking for a quick copy/paste for adding font MIME types to their .htaccess:
我刚刚对 IANA 官方列表做了一些研究。这似乎是截至 2013 年 5 月的当前状态:
这三个是官方的并由 IANA 分配:
这些不是官方/指定的,因此必须使用 'x-' 语法:
似乎“font”类型不存在,因此任何时候您看到“font/xxx”的类型都是假的。可能“x-font/xxx”是允许的,但不确定。 IIS8 附带了几个这样的条目。不确定 MS 是否认为这些“font/xxx”是为了兼容而需要的,或者它们只是不阅读 RFC :-)
application/font-woff 似乎是新的,也许自 2013 年 1 月以来只是官方的。所以“application/x -font-woff”在短期内可能更安全/更兼容。
I just did some research on IANA official list. This appears to be the current state of the play as at May 2013:
These three are official and assigned by IANA:
These are not not official/assigned, and so must use the 'x-' syntax:
It appears that the 'font' type does not exist, so any time type you see 'font/xxx' it is bogus. Possibly 'x-font/xxx' would be allowable, not sure. IIS8 ships with a couple entries like this. Not sure if MS thinks these 'font/xxx' ones are needed for compatibility, or if they just don't read RFCs :-)
The application/font-woff appears new and maybe only official since Jan 2013. So "application/x-font-woff" might be safer/more compatible in the short term.
通常,MIME 类型来自 RFC。
您在 IANA 网站 上有一份详尽的列表,但没有一个涉及该字体扩展。
此外,描述 WOFF 格式的文档是草案,并且不引用要使用的 mime 类型。
目前似乎没有关于该主题的可靠参考资料。
更新
W3C 现已发布 WOFF 作为建议,并在附录 B 中定义MIME 类型为
application/font-woff
。它还已添加到您现在提到的 IANA 网站。 -GKFXUsually, MIME types come from RFC.
You have a exhaustive list on the IANA site but none refers to the font extensions.
Moreover, document describing WOFF format is draft and does not refer to the mime type to use.
No reliable reference on the subject seems to exist for now.
Update
The W3C has now released WOFF as a recommendation, and in Appendix B defined the MIME type as
application/font-woff
. It's also been added to the IANA site that you mentioned now. -GKFX我认为值得一提的是,从 2013 年 3 月起,IANA 为
.otf
和.ttf
扩展提供 application/font-sfnt。有关官方 MIME 类型的完整最新列表,请参阅我的答案 字体的正确 MIME 类型
I think it's worth mentioning that, as from March 2013, IANA gave the
.otf
and.ttf
extentions the MIME type of application/font-sfnt.For a complete and current list of official MIME types, see my answer on Proper MIME type for fonts
2019 年您可以使用:
in 2019 you can use:
下面是在 apache 中缓存所有字体类型的示例(在 Google Page Speed 上测试):
Here a example for caching all font types in apache (tested on Google Page Speed):