Correct Apache AddType directives for font MIME types
Asked Answered
D

6

46

I’m using @font-face for embedded fonts (thanks Paul Irish). In trying to fix Chrome’s warning about wrong MIME type for woff fonts, I’ve discovered a mass of conflicting suggestions.

Everyone seems to agree that .eot fonts (for IE 6-8?) should be served using

AddType application/vnd.ms-fontobject .eot

For .ttf fonts (older non-IE browsers?) I’ve seen

AddType application/x-font-ttf        .ttf
AddType application/octet-stream      .ttf
AddType font/truetype                 .ttf
AddType font/ttf                      .ttf

And for .woff fonts (the new standard?) I’ve seen

AddType application/font-wof          .woff
AddType application/x-font-woff       .woff
AddType application/x-woff            .woff

I understand the correct MIME type for woff will be application/font-woff, but until the standard is official, application/x-font-woff is understood by Chrome.

I realise I’ve half answered my question in asking it, but the question is really: is there any authoritative guidance or further advice about what MIME types should be used for fonts?

Update (in case it’s of any help to anyone else): since there seems to be nothing authoritative, I’ve settled on using the following font MIME types in my .htaccess (which at least keeps Chrome happy):

AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf        .ttf
AddType application/x-font-woff       .woff
Destructor answered 14/9, 2011 at 11:32 Comment(2)
+1 I'm trying to put this in a framework so eventhough browsers can cope with application/octet-stream, I'd like to do this the 'right' way to ensure interoperability (e.g. allow users to enable gzip for certain content types)Tenure
Thanks for updating with what worked for you!Nether
R
4

Usually, MIME types come from RFC. You have a exhaustive list on the IANA site but none refers to the font extensions. Moreover, document describing WOFF format is draft and does not refer to the mime type to use. No reliable reference on the subject seems to exist for now.

Update

The W3C has now released WOFF as a recommendation, and in Appendix B defined the MIME type as application/font-woff. It's also been added to the IANA site that you mentioned now. -GKFX

Regent answered 28/10, 2011 at 9:36 Comment(1)
Hint: application/font-woff mime is now deprecated. Use font/woff instead. See IANA siteTemuco
G
77

I realize that this question is old, but for anyone looking for a quick copy/paste for adding font MIME types to their .htaccess:

<IfModule mod_mime.c>
    AddType application/vnd.ms-fontobject    .eot
    AddType application/x-font-opentype      .otf
    AddType image/svg+xml                    .svg
    AddType application/x-font-ttf           .ttf
    AddType application/font-woff            .woff
    AddType application/font-woff2           .woff2
</IfModule>
Genteel answered 24/8, 2013 at 0:20 Comment(4)
@Chris Clower here the link to my question help this toOverdrive
@VivekVikranth it should be able to be safely pasted anywhere in the .htaccess file, just be sure NOT to paste it inside of a set of tags, for example <IfModule>. Putting it on either the first line or last line of the file would work.Genteel
It's probably also worth noting that Apache's mime.types file lists all of these. A good way to check is to look at the server reponse header and see if has a content-type.Ashcan
@ChrisClower, why shouldn't this go inside tags? Should I also move out other lines such as those for css, html, jpg, and so on?Repugnance
P
7

I just did some research on IANA official list. 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"

It appears that the 'font' type does not exist, so any time type you see 'font/xxx' it is bogus. Possibly 'x-font/xxx' would be allowable, not sure. IIS8 ships with a couple entries like this. Not sure if MS thinks these 'font/xxx' ones are needed for compatibility, or if they just don't read RFCs :-)

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.

Phytophagous answered 9/5, 2013 at 6:22 Comment(0)
R
4

Usually, MIME types come from RFC. You have a exhaustive list on the IANA site but none refers to the font extensions. Moreover, document describing WOFF format is draft and does not refer to the mime type to use. No reliable reference on the subject seems to exist for now.

Update

The W3C has now released WOFF as a recommendation, and in Appendix B defined the MIME type as application/font-woff. It's also been added to the IANA site that you mentioned now. -GKFX

Regent answered 28/10, 2011 at 9:36 Comment(1)
Hint: application/font-woff mime is now deprecated. Use font/woff instead. See IANA siteTemuco
L
3

I think it's worth mentioning that, as from March 2013, IANA gave the .otf and .ttf extentions the MIME type of application/font-sfnt.

For a complete and current list of official MIME types, see my answer on Proper MIME type for fonts

Lanthanide answered 21/12, 2013 at 20:39 Comment(1)
Duplicate posts are auto-detected on SO, and you risk having both posts deleted.Vassell
S
3

in 2019 you can use:

AddType font/otf .otf
AddType font/ttf .ttf
AddType font/woff .woff
AddType font/woff2 .woff2
AddType application/vnd.ms-fontobject .eot
Slovenia answered 12/12, 2019 at 12:42 Comment(0)
A
1

Here a example for caching all font types in apache (tested on Google Page Speed):

AddType application/font-sfnt            otf ttf
AddType application/font-woff            woff
AddType application/font-woff2           woff2
AddType application/vnd.ms-fontobject    eot


ExpiresByType application/font-woff "access plus 1 month" 
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType application/font-sfnt "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
Aekerly answered 8/4, 2021 at 12:27 Comment(1)
Instead of application/font-woff you can just use the simpler font/woffFreshwater

© 2022 - 2024 — McMap. All rights reserved.