Precompiling CSS and JavaScript Assets

Rails 3.1 introduced the Sprockets based assets pipeline to precompile and merge all the different stylesheets into one and merge all the JavaScripts into one for the deployed web application. Precompiling and merging assets reduces the time to load web pages as fewer requests to assets are required. Also, if compression is used for assets compilation the amount of data transfer is reduced. Sprockets makes use of the manifest files app/assets/javascripts/application.js and app/assets/stylesheets/application.css, which contain directives, to select resources to merge and serve as static assets by the web server. By default, the application.js consists of require directives for the jquery.js and jquery_ujs.js that are in the Sprockets search path, and the require_tree directive to recursively include all JavaScript files in the specified directory, which is the ‘.’ directory (current directory). To include JavaScript files without recursion use the require_directory directive.