570

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

我提供 truetype (ttf) 字体font/truetype和 opentype (otf) as font/opentype,但我找不到 WOFF 字体的正确格式。

我已经尝试过font/woff,font/webopenfont/webopentype,但 Chrome 仍然抱怨:

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

有人知道吗?

4

17 回答 17

755

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

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

font/woff

font/woff2


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

application/x-font-woff

作为 WOFF 的 mime 类型。我知道这个变化现在在 Chrome 测试版中,如果还不稳定,它应该不会太远。

于 2011-02-28T13:01:13.057 回答
143

对我来说,下一个一直在 .htaccess 文件中工作。

AddType font/ttf .ttf
AddType font/eot .eot
AddType font/otf .otf
AddType font/woff .woff
AddType font/woff2 .woff2   
于 2011-10-03T08:27:15.007 回答
56

会的application/font-woff

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

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

来自 Mozilla css font-face notes

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

来源:https ://developer.mozilla.org/en/CSS/@font-face#Notes

于 2011-04-20T21:15:52.470 回答
28

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

通过 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 管理器

将 woff mime 类型添加到 IIS 的屏幕截图

于 2015-03-12T17:40:43.133 回答
23

NGINX 解决方案

文件

/etc/nginx/mime.types

或者

/usr/local/nginx/conf/mime.types

添加

font/ttf                      ttf;
font/opentype                 otf;
font/woff                     woff;
font/woff2                    woff2;
application/vnd.ms-fontobject eot;

消除

application/octet-stream        eot;

参考

RFC @02.2017

https://www.rfc-editor.org/rfc/rfc8081#page-15

https://www.iana.org/assignments/media-types/media-types.xhtml

感谢迈克富尔彻

http://drawingablank.me/blog/font-mime-types-in-nginx.html

于 2013-07-10T10:42:51.503 回答
21

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

font/woff
font/woff2
于 2017-06-22T20:31:31.163 回答
10

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

没有fontMIME 类型!因此,font/xxx总是错的。

于 2011-05-01T22:27:47.400 回答
5

为我做的事情是将其添加到我的 mime_types.rb 初始化程序中:

Rack::Mime::MIME_TYPES['.woff'] = 'font/woff'

清除缓存

rake tmp:cache:clear

在重新启动服务器之前。

来源:https ://github.com/sstephenson/sprockets/issues/366#issuecomment-9085509

于 2013-02-19T19:58:56.553 回答
5

将以下内容添加到您的 .htaccess

AddType font/woff woff

祝你好运

于 2013-06-04T12:47:51.180 回答
4

@尼科

目前还没有定义 woff 字体 mime 类型的标准。我使用字体交付 cdn 服务,它使用字体/woff,我在 chrome 中收到相同的警告。

参考:互联网号码分配机构

于 2010-09-04T05:30:38.077 回答
3

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types

这是一个有用的 mimetypes 列表

于 2019-03-28T11:02:55.033 回答
2

我知道这篇文章有点老了,但是在花了很多时间试图让字体在我的 nginx 本地机器上工作并尝试了大量的解决方案之后,我终于找到了一个对我有用的解决方案。

location ~* \.(eot|otf|ttf|woff|woff2)$ {
    add_header Access-Control-Allow-Origin *;
}

在括号内,您可以放置​​字体的扩展名或通常要加载的文件。例如,我也将它用于字体和图像(png、jpg 等),所以不要混淆这个解决方案仅适用于字体。

只需将其放入您的 nginx 配置文件,重新启动,我希望它也适用于您!

于 2018-07-19T15:12:22.123 回答
1

也许这会对某人有所帮助。我看到在 IIS 7.ttf上已经是一种已知的 mime 类型。它配置为:

application/octet-stream

所以我只是为所有 CSS 字体类型(.oet, .svg, .ttf, .woff)添加了它,并且 IIS 开始为它们提供服务。Chrome 开发工具也不会抱怨重新解释类型。

干杯,迈克尔

于 2012-03-20T16:56:41.697 回答
1

对于所有解决方案 index.php 都允许删除表单 url 和 woff 文件。在 .htaccess 文件中写入以下代码并对您的 application/config/config.php 文件进行此更改: $config['index_page'] = '';

仅适用于 Linux 托管服务器。 .htaccess 文件详细信息

AddType font/ttf .ttf
AddType font/eot .eot
AddType font/otf .otf
AddType font/woff .woff
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>
于 2015-06-29T05:09:29.637 回答
0

关闭:

  1. 网页开放字体格式
  2. 它可以使用 TrueType 或 PostScript (CFF) 轮廓进行编译
  3. 目前受 FireFox 3.6+ 支持

尝试添加:

AddType application/vnd.ms-fontobject .eot
AddType application/octet-stream .otf .ttf
于 2010-09-04T10:16:04.580 回答
0

IIS 自动将 .ttf 定义为 application/octet-stream 似乎工作正常,fontshop 建议将 .woff 定义为 application/octet-stream

于 2010-12-03T06:59:54.907 回答
-1

Mime 类型可能不是您唯一的问题。如果字体文件托管在 S3 或其他域上,您可能还会遇到 Firefox 不会从不同域加载字体的问题。使用 Apache 可以轻松修复,但在 Nginx 中,我读到您可能需要将字体文件编码为 base-64 并将它们直接嵌入到字体 css 文件中。

于 2013-02-25T20:32:21.987 回答