Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

//= require jquery //= require 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?

like image 732
Lai Yu-Hsuan Avatar asked Sep 20 '11 08:09

Lai Yu-Hsuan


People also ask

What is Require_tree?

The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file.

What does rake assets Precompile do?

rake assets:precompile. We use rake assets:precompile to precompile our assets before pushing code to production. This command precompiles assets and places them under the public/assets directory in our Rails application.

What are sprockets Rails?

Sprockets is a Ruby library for compiling and serving web assets. Sprockets allows to organize an application's JavaScript files into smaller more manageable chunks that can be distributed over a number of directories and files.


2 Answers

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

like image 82
thanikkal Avatar answered Sep 20 '22 18:09

thanikkal


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

like image 23
antonversal Avatar answered Sep 22 '22 18:09

antonversal