【问题标题】:HTTP Caching images (favicon) in Rails 4Rails 4 中的 HTTP 缓存图像(网站图标)
【发布时间】:2016-04-01 01:00:54
【问题描述】:

我在配置 Rails 4 以缓存图像时遇到问题。我正在使用 favicon 进行尝试,就实际性能提升而言,这可能是一个微不足道的案例,但无论如何我都想了解这方面。

我只是将网站图标放在我的public 文件夹中并以这种方式提供服务。我现在尝试通过一个简单的控制器来提供它,以便我可以在 ActionController 中使用 expires_in 方法(描述为 here)。

class DocumentsController < ApplicationController
  # ...

  def favicon
    expires_in 30.minutes, :public => true
    send_file Rails.root.join('public/', 'images/', 'favicon.ico'), type: 'image/x-icon', disposition: 'inline'
  end
end

但没有骰子。当我请求图像时,这是我在网络检查器中看到的 -

如您所见,它没有被缓存。有什么建议吗?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 caching http-caching


    【解决方案1】:

    可能 catch 位于缓存配置中。 在/config/development.rb/config/production.rb

    # ...
    config.action_controller.perform_caching = true
    # ...
    

    【讨论】:

    • 是的,我也想过。不幸的是,不是这样,我一直启用它
    • 查看这个答案:link
    猜你喜欢
    • 2010-10-01
    • 2011-08-09
    • 1970-01-01
    • 2017-08-21
    • 2012-09-12
    • 2011-10-08
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多