我正在使用 Ryan Bates 的漂亮布局,其中包括带有以下代码的布局助手。
在我的application.html.erb中
<%= stylesheet_link_tag "application", :cache => true %>
<%= javascript_include_tag :defaults, :cache => true %>
<%= yield(:head) %>
然后在助手layout_helper.rb中
def stylesheet(*args)
content_for(:head) { stylesheet_link_tag(*args) }
end
def javascript(*args)
content_for(:head) { javascript_include_tag(*args) }
end
在我的应用程序中使用它,我可以通过调用从任何页面添加 css 和 javascript
<% javascript "what_ever" %>
<% stylesheet "what_ever" %>
但我面临的问题是这些额外的 css 或 js 文件没有得到 :cache => true,因此不会被缓存。
有办法解决这个问题吗?
基本上,我希望每个页面都有一个小的 css 文件,然后在调用时提供一个大文件。
最佳答案
会使用
<% javascript "what_ever", :cache => true %>
不工作?
查看 javascript_include_tag 文档 http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-stylesheet_link_tag应该的。
关于javascript - 导轨 : how to cache css and js files when using this method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6842908/