开发者

what's the reason behind the default require_tree in asset pipeline?

开发者 https://www.devze.com 2023-04-05 21:26 出处:网络
When using asset pipeline in rails 3.1, it creates a default application.js: //= require jquery //= requir开发者_开发问答e jquery_ujs

When using asset pipeline in rails 3.1, it creates a default application.js:

//= require jquery
//= requir开发者_开发问答e jquery_ujs
//= require_tree .

but when will I need include all of my javascript? In most cases we use different javascrips for different controllers/views?


require_tree . will result in you having a single file (application.js in this case) holding all your scripts that is there in the folder. And the fact that browsers will only pull that file once from your web server (unless you do a Ctrl + R refresh or there is a change in file cache property), does make the apps behave faster for subsequent requests.

Unless of course you have an application that have quite varying and huge scripts and a typical user is not expected to move around much that he wouldn't need majority of those. Which obviously is not very common case.

for additional and detailed information. look here http://guides.rubyonrails.org/asset_pipeline.html


Browser loads application.js once and then gets it from cache.


//= require_tree . loads the every file or sub folder file within the javascript directory

0

精彩评论

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