Proper MIME type for fonts

2019-01-01 08:10发布

Searching the web, I find heaps of different suggestions for what the proper MIME type for a font is, but I have yet to try any MIME type that rids me of a Chrome warning such as the following:

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

The font is an OTF.

I've tried the following MIME types so far

  • font/otf
  • application/font-otf
  • application/font
  • application/otf
  • application/octet-stream
  • application/x-font-otf
  • application/x-font-TrueType (I know it's not truetype, but one source quoted this for OTF)

标签: mime fonts
14条回答
十年一品温如言
2楼-- · 2019-01-01 08:20

As of February 2017, RFC 8081 adds font/* media types, which are also listed in the IANA Media Types list. font/otf is in this list.

查看更多
梦寄多情
3楼-- · 2019-01-01 08:20

Maybe this will help someone. I saw that on IIS 7 .ttf is already a known mime-type. It's configured as:

application/octet-stream

So I just added that for all the CSS font types (.oet, .svg, .ttf, .woff) and IIS started serving them. Chrome dev tools also do not complain about re-interpreting the type.

Cheers, Michael

查看更多
梦寄多情
4楼-- · 2019-01-01 08:21

I just did some research on IANA official list. I believe the answer given here 'font/xxx' is incorrect as there is no 'font' type in the MIME standard.

Based on the RFCs and IANA, this appears to be the current state of the play as at May 2013:

These three are official and assigned by IANA:

  • svg as "image/svg+xml"
  • woff as "application/font-woff"
  • eot as "application/vnd.ms-fontobject"

These are not not official/assigned, and so must use the 'x-' syntax:

  • ttf as "application/x-font-ttf"
  • otf as "application/x-font-opentype"

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.

查看更多
荒废的爱情
5楼-- · 2019-01-01 08:23

FWIW regarding Apache 2.2 VirtualHosting and mod_mime tested on Debian Linux and OS X Leopard and Snow Leopard:

If you have a VirtualHost configuration you will want to add the types via the AddType Directive as follows at least at the bottom of the configuration as follows:

....
   AddType font/opentype .otf
   AddType font/ttf .ttf
</VirtualHost>

Tested against Chrome Unstable/Trunk and Safari WebKit Nightly which eliminates the mime octet-stream warnings for both the ttf and otf font types.

Note: .htaccess has zero effect when dealing with VirtualHosting. If you're developing for several sites you'll be using VirtualHosting development and each configuration will need these AddType additions.

查看更多
永恒的永恒
6楼-- · 2019-01-01 08:28

As there's still a lot of confusion on the web about MIME types for web fonts, I thought I'd give a current answer, complete with effective dates, and supporting links to IANA and the W3C.

Here are the official MIME types for Web Fonts:

Note there is a movement to change all the above to MIME types of font/XXX, as backed by the W3C in its proposal for WOFF v2. This is being tracked by the Internet Engineering Task Force (IETF) under The font Top Level Type and in February 2017 was approved RFC status (see RFC 8081) so it may all change yet!

While on the topic of web servers, it's worth mentioning that HTTP responses may gzip (or otherwise compress) all the above font formats except .woff & .woff2 which are already heavily compressed.

I say more in MIME Types for Web Fonts with (Fantom) BedSheet.

查看更多
泛滥B
7楼-- · 2019-01-01 08:28

Here is NGINX solution

file

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

add

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

remove

application/octet-stream        eot;

Thanks to Mike Fulcher

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

查看更多
登录 后发表回答