本文介绍了.woff2 字体的正确 MIME 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我将 Font Awesome 包更新到 4.3.0 并注意到 woff2 字体加入.该文件在 CSS 中链接,因此我需要配置 nginx 以正确提供 woff2 文件.

Today I updated Font Awesome package to 4.3.0 and noticed that woff2 font was added. That file is linked in CSS so I need to configure nginx to serve woff2 files properly.

目前我在 nginx 配置中有这个字体块:

Currently I have this block in nginx config for fonts:

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 类型是什么?

What is proper mime type for woff2 fonts?

推荐答案

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

In IIS you can declare the mime type for WOFF2 font files by adding the following to your project's web.config:

<system.webServer>
  <staticContent>
    <remove fileExtension=".woff2" />
    <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
  </staticContent>
</system.webServer>

更新:根据最新的W3C Editor's Draft WOFF2 规范,mime 类型可能会发生变化.请参阅附录 A:互联网媒体类型注册部分 6.5.WOFF 2.0 指出最新的提议 格式是 font/woff2

Update:The mime type may be changing according to the latest W3C Editor's Draft WOFF2 spec. See Appendix A: Internet Media Type Registration section 6.5. WOFF 2.0 which states the latest proposed format is font/woff2

这篇关于.woff2 字体的正确 MIME 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 18:03