3

这是我所做的:

首先,我在目录中创建了一个fonts文件夹app/assets


然后我配置了资产管道以识别这个新文件夹。

config/environments/development.rb

# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf .otf )

接下来,我在中配置 mime 类型config/initializers/mime_types.rb

# Be sure to restart your server when you modify this file.

# Here are some example that came with the default Rails project.

# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone

Rack::Mime::MIME_TYPES['.otf'] = 'application/x-font-opentype'

最后,我在 SCSS 中引用了字体:

@font-face {
  font-family: 'ArnoProDisplay';
  src: url('ArnoPro-Display.otf');
  font-weight: normal;
  font-style: normal;
}

我正在使用谷歌浏览器,控制台说:

Resource interpreted as Font but transferred with MIME type
application/vnd.oasis.opendocument.formula-template: 
"http://localhost:3000/assets/ArnoPro-Display.otf".

我可以在“网络”选项卡中正确看到字体:

在此处输入图像描述

4

1 回答 1

9

更新

解决方案 1

更改application/x-font-opentypefont/opentype。来源:字体mime类型

Rack::Mime::MIME_TYPES['.otf'] = 'font/opentype'

并清除缓存

rake tmp:cache:clear

在重新启动服务器之前。


如果解决方案 1不起作用,您应该创建文件.htaccess并添加它

AddType application/vnd.oasis.opendocument.formula-template .otf

于 2013-05-29T15:15:37.367 回答