Capistrano: Speeding up 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.

Adding the asset cache directory to symlinked directories

Popular asset managers for Rails are Sprockets and Webpacker. Both keep a cache of already compiled files that we're going to leverage for deployments now.

  • Sprockets cache directory: tmp/cache/assets/sprockets
  • Webpacker cache directory: tmp/cache/webpacker (check cache_path: in config/webpacker.yml to be sure)

In Capistrano 3, add the cache directory to your linked directories:

# deploy.rb
set :linked_dirs, %w[log public/system … $cache-directory]

If you want to do this for a specific stage only, do this instead:

# deploy/staging.rb
append :linked_dirs, $cache-directory

In Capistrano 2 you need to link the directory manually.

Dominik Schöler Over 5 years ago