fonts - OTF 字体的正确 MIME 类型

标签 fonts mime opentype

在网上搜索时,我发现了很多有关字体正确 MIME 类型的不同建议,但我还没有尝试过任何可以消除 Chrome 警告的 MIME 类型,如下所示:

Resource interpreted as font but transferred with MIME type font/otf

该字体是 OTF。

到目前为止我已经尝试过以下 MIME 类型

  • 字体/otf
  • 应用程序/font-otf
  • 应用程序/字体
  • 应用程序/otf
  • 应用程序/八位字节流
  • 应用程序/x-font-otf
  • application/x-font-TrueType(我知道这不是 truetype,但一位消息人士在 OTF 中引用了这一点)

最佳答案

在 Apache 和 IIS 服务器上,可以为多种字体格式设置 MIME 类型。 I've traditionally had luck具有以下内容:

svg   as "image/svg+xml"                  (W3C: August 2011)
ttf   as "application/x-font-ttf"         (IANA: March 2013)
      or "application/x-font-truetype"
otf   as "application/x-font-opentype"    (IANA: March 2013)
woff  as "application/font-woff"          (IANA: January 2013)
woff2 as "application/font-woff2"         (W3C W./E.Draft: May 2014/March 2016)
eot   as "application/vnd.ms-fontobject"  (IANA: December 2005)
sfnt  as "application/font-sfnt"          (IANA: March 2013) 

根据维护有关多用途互联网邮件扩展(MIME 类型)初始文档的互联网工程任务组的说法:https://www.rfc-editor.org/rfc/rfc2045#section-5 ...它具体说:

"It is expected that additions to the larger set of supported types can generally be accomplished by the creation of new subtypes of these initial types. In the future, more top-level types may be defined only by a standards-track extension to this standard. If another top-level type is to be used for any reason, it must be given a name starting with "X-" to indicate its non-standard status and to avoid a potential conflict with a future official name."

事实上,随着时间的推移,随着标准的创建和接受,其他 MIME 类型也会被添加,因此我们看到了供应商特定 MIME 类型的示例,例如 vnd.ms-fontobject 等。

2013 年 8 月 16 日更新:WOFF 为 formally registered at IANA on January 3, 2013Webkit has been updated on March 5, 2013在最新版本中获取此更新的浏览器将开始使用旧的 x-font-woff 声明发出有关服务器 MIME 类型的警告。由于警告只是烦人,我建议立即切换到批准的 MIME 类型。在理想的情况下,警告会及时解决。

2015 年 2 月 26 日更新:WOFF2 现已包含在 W3C 编辑草案中,并包含提议的 mime 类型。它可能会按照最近的进展时间表在明年(可能是 2016 年底)提交给 IANA。以及 SFNT,Google Web Fonts with their sfntly java library 的主干表引用中使用的可缩放/样条容器字体格式。已经是 registered as a mime type with IANA并可以根据个人需要添加到此列表中。

2017 年 10 月 4 日更新:我们可以跟踪 WOFF2 格式的进展 here大多数现代浏览器都成功支持该格式。同样,我们可以遵循 IETF 的“字体”顶级媒体类型征求意见 (RFC) trackerdocument关于供批准的最新提议字体类型集。

<小时/>

对于那些希望在 CSS 中以正确顺序嵌入字体的人,请访问 this article 。但同样,我很幸运地执行了以下命令:

@font-face {
    font-family: 'my-web-font';
    src: url('webfont.eot');
    src: url('webfont.eot?#iefix') format('embedded-opentype'),
         url('webfont.woff2') format('woff2'),
         url('webfont.woff') format('woff'),
         url('webfont.ttf') format('truetype'),
         url('webfont.svg#webfont') format('svg');
    font-weight: normal;
    font-style: normal;
}
<小时/>

对于 Subversion 自动属性,这些属性可以列出为:

# Font formats
svg   = svn:mime-type=image/svg+xml
ttf   = svn:mime-type=application/x-font-ttf
otf   = svn:mime-type=application/x-font-opentype
woff  = svn:mime-type=application/font-woff
woff2 = svn:mime-type=application/font-woff2
eot   = svn:mime-type=application/vnd.ms-fontobject
sfnt  = svn:mime-type=application/font-sfnt

关于fonts - OTF 字体的正确 MIME 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2871655/

相关文章:

android - 在 iOS 中的 UITextView 上加载 html 中的字体时出现问题

java - 字体对象 - 使用 Windows 光栅字体

css - Bootstrap 图标字体未加载

css - 在字体中添加国际字符?

android - 在 Android 中为通用文件选择哪种 mimeType?

html - 使用tcl在电子邮件中写彩色字体

fonts - 无法解码 OpenType Roboto

fonts - 如何在 Visual Studio Code 中启用递归 (OpenType) 字体代码连字?

javascript - 如何在 Web 应用程序中显示 HTML 电子邮件?

javascript - 将 paper.js 路径转换为 ​​opentype.js 路径