Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 web font (woff) mime type

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

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"

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

like image 560
panzi Avatar asked Sep 28 '12 17:09

panzi


1 Answers

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'

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

like image 82
ecmanaut Avatar answered Sep 25 '22 06:09

ecmanaut