直接从app服务器提供字体资源

时间:2014-08-23 01:58:26

标签: ruby-on-rails sass

在我的rails应用程序中,我通过CDN提供所有资产。我想直接从我的应用服务器上提供我的字体。 font_url / font-url将始终包含cdn url。有没有方便的方法来生成字体路径(带摘要),而不包括CDN域或协议(http [s])?

我唯一能想到的就是编写自己的方法来复制asset_path的功能 - 希望有更优雅的方法来实现这一目标。

更新 - 背景

我想将我的主域中的字体仅提供给IE用户,这样他们就不会在高安全性的情况下中断#34;模式。

1 个答案:

答案 0 :(得分:1)

<强>更新

  1. 将字体文件复制到一个单独的文件夹中,例如“ie-high-security”。这是为了在步骤#2中识别它们。

  2. 通过在“config / application.rb”中配置asset_host来提供文件夹中的文件(示例中为“ie-high-security”):

    ActionController::Base.asset_host = Proc.new { |source|
     if source.include?('/ie-high-security/')
       ""
     else
       "http://assets.example.com"
      end
    }
    
  3. 在仅适用于IE9的单独样式表中引用“ie-high-security”文件夹中的字体。

  4. 按照https://stackoverflow.com/a/25415002/368697

    中的建议,为IE9样式表提供条件评论
    <!--[if IE 9]>
      stylesheet using internally served fonts
    <![endif]-->
    
  5. 旧建议:

    使用font_path代替font_url。第一种方法生成绝对路径,而不预先设置资产主机。

    如果从CDN提供的样式表中包含该字体,则需要一条返回应用服务器的完整路径。

相关问题