The asset pipeline is enabled by default but will look a little strange if you are migrating from an older version of Ruby on Rails. Let's have a quick look.
There are a few more steps involved to make this work in production. Wouldn't it be nice to pre-compress the assets for production to save some precious processor time? Let's compress the assets right after our Capistrano deployment:
After deploying your code to production you should see a new /public/assets folder with your compressed files (a MD5 hash has been added to the filenames). The hash makes it possible for browsers to cach the files indefinitly. As long as the filename is the same there is no need to fetch the file again after it has been downloaded. Change your code and deploy again and you'll see the hashes have changed.
So far so good but you may have noticed all images referenced in the stylesheets are gone. Well, the image filenames now include the MD5 hash so the browser is looking for logo.png and doesn't find anything. Instead it should look for somthing like logo-d41d8cd98f00b204e9800998ecf8427e.png. Lets make our CSS a bit more dynamic.
First rename all your /assets/stylesheets CSS files to something ERB will understand: e.g. default.css.erb. This allows us to use ERB in the stylesheets. Now change all the image references to:
Deploy your application again and you should be good to go. All image references in you stylesheets have been replaced by their ‘hashed’ version.
This post is open source. Did you spot a mistake? Ideas for improvements? Contribute to this post via Github. Thank you!