繁体   English   中英

自定义字体在heroku中不起作用

[英]Custom font not working in heroku

使用Rails 4

我已经阅读了很多关于如何让我的自定义字体在heroku中工作的线程。 他们在开发模式下本地工作,但当推到heroku时,他们不会出现。

我的@ font-face位于主样式表中

@font-face {
    font-family: 'caviar_dreamsregular';
    src: font-url('caviardreams-webfont.eot');
    src: font-url('caviardreams-webfont.eot?#iefix') format('embedded-opentype'),
         font-url('caviardreams-webfont.woff') format('woff'),
         font-url('caviardreams-webfont.ttf') format('truetype'),
         font-url('caviardreams-webfont.svg#caviar_dreamsregular') format('svg');
    font-weight: normal;
    font-style: normal;

}

application.rb中

config.assets.paths << "#{Rails.root}/app/assets/fonts"

我有预编译资产

rake assets:precompile

Heroku日志中没有错误。

不能想出来,有没有人有任何建议?

更新:

访问我的手机上的网站,字体工作...清除计算机上的缓存,仍然无法在计算机上工作。

这可能是几个问题; 最值得注意的是,我建议你不要使用动态资产路径:


指纹

当您预编译资产时,Rails使用资产指纹识别

这样做的原因是允许将每个资产单独分配给系统,从而提供更健壮的结构(或某种东西)。 基本上,它会在资产文件名的末尾添加MD5哈希值:

global-908e25f4bf641868d8683022a5b62f54.css

路径

因为动态指纹识别使所有预编译资产具有不同的名称,所以您需要使用Rails的动态路径助手:

#app/assets/stylesheets/application.css.scss
@font-face {
    font-family: 'caviar_dreamsregular';
    src: asset-url('caviardreams-webfont.eot');
    src: asset-url('caviardreams-webfont.eot?#iefix') format('embedded-opentype'),
         asset-url('caviardreams-webfont.woff') format('woff'),
         asset-url('caviardreams-webfont.ttf') format('truetype'),
         asset-url('caviardreams-webfont.svg#caviar_dreamsregular') format('svg');
    font-weight: normal;
    font-style: normal;
}

您需要使用动态样式表引擎(如SASS)来处理动态路径

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM