Capistrano: Speeding up Sprockets' asset compile during deploy
Remember How to skip Sprockets asset compile during Capistrano deployment and Automatically skipping asset compilation when assets have not changed? Turns out there is an even better way to speed up Capistrano deployments with asset compilation – and it's even simpler.
Sprockets is the library behind Rails' asset pipeline. It keeps a cache of already compiled files, so when a single file changes, it only needs to rebuild that one. This is exactly what makes asset compilation so fast in development. We're gonna leverage the cache for deployments now.
In Capistrano 3, add
tmp/cache/assets/sprockets to your linked directories:
# deploy.rb set :linked_dirs, %w[log public/system tmp/cache/assets/sprockets …]
If you want to do this for a specific stage only, do this instead:
# deploy/staging.rb append :linked_dirs, 'tmp/cache/assets/sprockets'
In Capistrano 2 you need to link the directory manually.