Rails 3 Web字体(WOFF)MIME类型 [英] Rails 3 web font (woff) mime type

查看:115
本文介绍了Rails 3 Web字体(WOFF)MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们从静态资产中提供一些Web字体(.woff),我想设置正确的mime类型(application/x-font-woff).我尝试在config/initializers/mime_types.rb中执行此操作,但没有效果:

We serve some web fonts (.woff) from our static assets and I would like to set the correct mime type (application/x-font-woff). I tried to do this in config/initializers/mime_types.rb but it had no effect:

Mime::Type.register "application/x-font-woff", :woff

返回的mime类型仍然保持为application/octet-stream.我什至尝试添加此行(因为它是rails源中唯一可以找到字符串"woff"的其他位置):

The returned mime type still stayed application/octet-stream. I even tried to add this line (because it was the only other place in the rails source where I could find the string "woff"):

Rack::Mime::MIME_TYPES[".woff"] = "application/x-font-woff"

但是它仍然没有帮助.如何正确设置网络字体的mime类型?

But it still didn't help. How do I properly set the mime type for web fonts?

推荐答案

直到机架将其MIME类型列表修复为正确的woff,临时破解确实是您的config/initializers/mime_types.rb行:

Until Rack fixes its MIME-type list to a correct woff, the interim hack is indeed your config/initializers/mime_types.rb line:

# tell Rack (and Sprockets) about modern font MIME types:
Rack::Mime::MIME_TYPES['.woff'] = 'application/x-font-woff'

但是,要使其真正生效,您必须擦除tmp/cache并重新启动服务器.

To have it actually take effect, though, you have to wipe tmp/cache and restart your server.

这篇关于Rails 3 Web字体(WOFF)MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆