.woff2字体的正确MIME类型

Proper MIME type for .woff2 fonts

今天,我将Font Awesome软件包更新为4.3.0,并注意到添加了woff2字体。 该文件在CSS中链接,因此我需要配置nginx才能正确提供woff2文件。

目前,我在nginx config中有此字体块:

1
2
3
4
5
6
location ~* \.(otf|eot|woff|ttf)$ {
    types     {font/opentype otf;}
    types     {application/vnd.ms-fontobject eot;}
    types     {font/truetype ttf;}
    types     {application/font-woff woff;}
}

woff2字体正确的mime类型是什么?


在IIS中,可以通过将以下内容添加到项目的web.config中来声明WOFF2字体文件的mime类型:

1
2
3
4
5
6
<system.webServer>
  <staticContent>
    <remove fileExtension=".woff2" />
    <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
  </staticContent>
</system.webServer>

更新:
根据最新的W3C编辑器的WOFF2草案规范,mime类型可能会发生变化。请参阅附录A:" Internet媒体类型注册"第6.5节。 WOFF 2.0指出最新提议的格式为font/woff2


font/woff2

对于nginx,将以下内容添加到mime.types文件:

font/woff2 woff2;

旧答案

WOFF2字体的mime类型(有时称为mimetype)已被提出为application/font-woff2

另外,如果您参考规范(http://dev.w3.org/webfonts/WOFF2/spec/),则会看到正在讨论font/woff2。我怀疑所有字体的孝顺哑剧类型最终将变得更合乎逻辑的font/*(font/ttffont/woff2等)...

N.B. WOFF2仍处于"工作草案"状态-尚未正式通过。


阿帕奇

在Apache中,您可以按照此链接所述通过.htaccess文件添加woff2 MIME类型。

1
AddType  application/font-woff2  .woff2

IIS

在IIS中,只需将以下mimeMap标记添加到staticContent标记内的web.config文件中。

1
2
3
4
<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />


http://dev.w3.org/webfonts/WOFF2/spec/#IMT

似乎w3c将其切换为font/woff2

我看到有人在讨论适当的mime类型。
在链接中,我们读到:

This document defines a top-level MIME type"font" ...

... the officially defined IANA subtypes such as"application/font-woff" ...

The members of the W3C WebFonts WG believe the use of"application" top-level type is not ideal.

然后

1
2
3
4
5
6
7
8
6.5. WOFF 2.0

    Type name:

        font
    Subtype name:

        woff2

因此,W3C的主张与IANA有所不同。

我们可以看到它也不同于woff类型:
http://dev.w3.org/webfonts/WOFF/spec/#IMT
我们在哪里阅读:

1
2
3
4
5
6
Type name:

    application
Subtype name:

    font-woff

这是

1
application/font-woff

http://www.w3.org/TR/WOFF/#appendix-b