Read more

How to skip Sprockets asset compile during Capistrano deployment

Arne Hartherz
March 22, 2018Software engineer at makandra GmbH

Prefer to configure Capistrano so Sprockets can reuse its asset cache: https://makandracards.com/makandra/60699-capistrano-speeding-up-sprockets-asset-compile-during-deploy

For applications coming with lots of stylesheets and scripts, asset compilation might take quite long. This can be annoying when deploying a release that does not actually change assets.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

When your app uses Sprockets, you can simply skip asset compilation and re-use the previous release's assets. [1]
That is especially easy via Capistrano. Capistrano will automatically symlink your release's public/assets to a shared directory, so all you need to do is skip the deploy:assets:precompile task.

Put the following code where you'd put other custom Capistrano tasks (default is lib/capistrano/tasks/*.rake)

if ENV['SKIP_ASSETS']
  Rake::Task['deploy:assets:precompile'].clear_actions
end

You can then set the above environment variable when deploying:

SKIP_ASSETS=1 cap staging deploy

Enjoy.


[1] Sprockets will pick any public/assets/.sprocket-manifest-*.json.

Posted by Arne Hartherz to makandra dev (2018-03-22 13:40)