In web application today that are very common that we have 3 to 5+ script and CSS files. Using Jammit we can combine (or in this context: package) all scripts into a single script, and similarly combine all CSS into single stylesheet. Reducing the number of HTTP requests can lead to a faster page loading.
In your Gemfile
gem 'jammit', '~> 0.6.3', :groups => [:development, :production]
$ bundle install
I put jammit on development too since I want to check the joint script and stylesheet is working.
config/assets.yml. Here is an example
See here for complete configuration options that you may add to assets.yml
In your layout
In development, no packaging is performed, unless package_assets is set to "always".
- Include only script and CSS that you need
- Pay attention on the file order. You need to know what file that must be loaded first before others.
- Using above method, jammit will try to package and compress script and CSS files by request, it is better if you can use Jammit within your Rakefile and run the task only when you need to deploy your application to a production server.