开发者

cache Javascripts in different views - under same name

开发者 https://www.devze.com 2023-04-03 13:01 出处:网络
I have a few JavaScript that I would like to cache as follow : layout1.erb has ......... <%=javascript_include_tag \'jquery.min\' ,

I have a few JavaScript that I would like to cache as follow :

layout1.erb has

.........
  <%=  javascript_include_tag 'jquery.min' ,
    'rails_ujs',
    'qwerty',
    'jquery_editinplace',
    'jquery.livequery',
    'jquery.validate',
    'ddsmoothmenu',
    :cache=>"main_js_cache"
%>
...开发者_StackOverflow中文版.......

layout2.erb

.........
  <%=  javascript_include_tag 'jquery.min' ,
    'rails_ujs',
    'qwerty',
    'jquery_editinplace',
    'jquery.livequery',
    'jquery.validate',
    'ddsmoothmenu',
    :cache=>"main_js_cache"
%>
..........

Now since the cache file name is same would the same be used or will it be generated again & again ?


I found the answer.. Left the question open incase others find it useful..

This is how caching goes..

First time suppose you render layout2.erb .. then it combines and generates a file called as "main_js_cache".

Next time you again render layout2.erb then it will just directly throw "main_js_cache" without regenerating it.

Suppose you render layout1.ebr in that case rails just looks for a file called "main_js_cache" it finds it and so it does NOT generate a new file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号