WOFF字体应该作为什么mime类型?
我正在服务truetype (ttf)字体作为字体/truetype和opentype (otf)作为字体/opentype,但我找不到WOFF字体的正确格式。
我已经尝试了字体/woff,字体/webopen,和字体/webopentype,但Chrome仍然抱怨:
资源解释为字体,但使用MIME类型应用程序/字节流传输。
有人知道吗?
WOFF字体应该作为什么mime类型?
我正在服务truetype (ttf)字体作为字体/truetype和opentype (otf)作为字体/opentype,但我找不到WOFF字体的正确格式。
我已经尝试了字体/woff,字体/webopen,和字体/webopentype,但Chrome仍然抱怨:
资源解释为字体,但使用MIME类型应用程序/字节流传输。
有人知道吗?
当前回答
对于所有解决方案index.php删除表单url和woff文件允许。为了在.htaccess文件中编写以下代码,并对应用程序/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>
其他回答
为我做的事情是将这个添加到我的mime_types中。rb初始化:
Rack::Mime::MIME_TYPES['.woff'] = 'font/woff'
然后清空缓存
rake tmp:cache:clear
在重新启动服务器之前。
来源:https://github.com/sstephenson/sprockets/issues/366 # issuecomment - 9085509
它将是application/font-woff。
参见http://www.w3.org/TR/WOFF/#appendix-b (W3C候选推荐2011年8月04日)
和http://www.w3.org/2002/06/registering-mediatype.html
来自Mozilla css字体面注释
在Gecko中,web字体受到相同的域限制(字体文件必须与使用它们的页面在相同的域上),除非使用HTTP访问控制来放松这一限制。 注意:由于没有为TrueType、OpenType和WOFF字体定义MIME类型,因此不考虑指定文件的MIME类型。
来源:https://developer.mozilla.org/en/CSS/@font-face笔记
将以下内容添加到.htaccess中
AddType font/woff woff
祝你好运
IIS自动将.ttf定义为应用程序/octet-stream,这似乎工作正常,而fontshop建议将.woff定义为应用程序/octet-stream
Mime类型可能不是你唯一的问题。如果字体文件托管在S3或其他域上,您可能还会遇到Firefox无法从不同域加载字体的问题。这在Apache上很容易解决,但在Nginx上,我读到你可能需要用base-64编码你的字体文件,并直接嵌入到你的字体css文件中。