首页 文章

WOFF字体的Mime类型?

提问于
浏览
533

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

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

我试过 font/wofffont/webopenfont/webopentype ,但Chrome仍然抱怨:

“资源被解释为字体,但使用MIME类型application / octet-stream进行传输 . ”

有人知道吗?

17 回答

  • 1

    Mime类型可能不是您唯一的问题 . 如果字体文件托管在S3或其他域上,您可能还会遇到Firefox不会从不同域加载字体的问题 . 这是Apache的一个简单修复,但在Nginx中,我已经读过你可能需要在base-64中编码你的字体文件并将它们直接嵌入你的font css文件中 .

  • 128

    Update from Keith Shaw's comment on Jun 22, 2017:

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


    在2011年1月it was announced,同时Chromium将承认

    application/x-font-woff

    作为WOFF的哑剧型 . 我知道这个变化现在已经在Chrome测试版中,如果还没有稳定,那么它应该不会太远 .

  • 5

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

    AddType font/ttf .ttf
    AddType font/eot .eot
    AddType font/otf .otf
    AddType font/woff .woff
    AddType font/woff2 .woff2
    
  • 3

    它将是 application/font-woff .

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

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

    From Mozilla css font-face notes

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

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

  • 0

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

    via 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="application/font-woff" />
         <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
      </staticContent>
    </system.webServer>
    

    via IIS Manager

    screenshot of adding woff mime types to IIS

  • 20

    NGINX SOLUTION

    文件

    /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;
    

    REFERENCES

    RFC @ 02.2017

    https://tools.ietf.org/html/rfc8081#page-15

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

    感谢Mike Fulcher

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

  • 718

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

    font/woff
    font/woff2
    
  • 16

    没有 font MIME类型!因此, font/xxx 总是错的 .

  • 3

    @Nico

    目前,没有为woff字体mime类型定义的标准 . 我使用字体传递cdn服务,它使用font / woff,我在chrome中得到相同的警告 .

    参考:The Internet Assigned Numbers Authority

  • 12

    对我这样做的事情是将它添加到我的mime_types.rb初始化器:

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

    and 清除缓存

    rake tmp:cache:clear
    

    在重新启动服务器之前 .

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

  • 1

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

    application/octet-stream
    

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

    干杯,迈克尔

  • 2

    将以下内容添加到.htaccess中

    AddType font/woff woff
    

    祝好运

  • 0

    WOFF:

    • Web Open字体格式

    • 可以使用TrueType或PostScript(CFF)轮廓进行编译

    • 目前FireFox 3.6支持它

    尝试添加:

    AddType application/vnd.ms-fontobject .eot
    AddType application/octet-stream .otf .ttf
    
  • 6

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

  • 23

    For all Solution index.php remove form url and woff file allowed. for write below code in .htaccess file and and make this alternation to your application/config/config.php file: $config['index_page'] = '';

    For only Linux hosting server. .htaccess file details

    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>
    
  • 1

    我知道这篇文章有点陈旧但是花了很多时间试图让我的nginx本地机器上的字体工作并尝试了大量的解决方案后我终于得到了一个对我有用的东西就像一个魅力 .

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

    在括号内,您可以放置字体的扩展名,或者通常是要加载的文件 . 例如,我用它来表示字体和图像(png,jpg等),所以不要混淆这个解决方案只适用于字体 .

    只需将它放入你的nginx配置文件,重启,我希望它也适合你!

  • 56

    我遇到了同样的问题, font/opentype 为我工作

相关问题