admin管理员组文章数量:1278822
I am using GTMetrix to see my site speed and it is showing me this (check below image).
How can I Leverage browser caching to speed up the site loading speed in Rails 4?
To defer parsing JS, I have already put
<%= javascript_include_tag 'application' %>
before /html tag.
I am using GTMetrix to see my site speed and it is showing me this (check below image).
How can I Leverage browser caching to speed up the site loading speed in Rails 4?
To defer parsing JS, I have already put
<%= javascript_include_tag 'application' %>
before /html tag.
Share Improve this question asked Jan 19, 2017 at 12:20 iCyborgiCyborg 4,72815 gold badges57 silver badges86 bronze badges1 Answer
Reset to default 14I would remend using separate web server, like NGINX to set cache headers for .js and .css files, removing the hassle of serving static files from Rails.
If you really wanna go with a pure Rails (app/web)server, the solution is putting this piece of code in config/environments/production.rb
RAILS 5
config.public_file_server.headers = {
'Cache-Control' => "public, s-maxage=#{365.days.to_i}, maxage=#{180.days.to_i}",
'Expires' => "#{1.year.from_now.to_formatted_s(:rfc822)}"
}
RAILS 4
config.static_cache_control = "public, s-maxage=#{365.days.to_i}, maxage=#{180.days.to_i}"
本文标签: javascriptHow to leverage browser caching in Rails 4Stack Overflow
版权声明:本文标题:javascript - How to leverage browser caching in Rails 4? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741284724a2370203.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论