Correct Apache AddType directives for font MIME types

前端 未结 5 1380
臣服心动
臣服心动 2020-11-30 01:06

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 su

相关标签:
5条回答
  • 2020-11-30 01:35

    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.

    0 讨论(0)
  • 2020-11-30 01:44

    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

    0 讨论(0)
  • 2020-11-30 01:44

    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
    
    0 讨论(0)
  • 2020-11-30 01:47

    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

    0 讨论(0)
  • 2020-11-30 01:55

    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>
    
    0 讨论(0)
提交回复
热议问题