Speeding up Capistrano Deployments from 6 Minutes to 9 Seconds by Skipping Asset Compilation

By skipping assets:precompile when assets haven’t changed, I’ve reduced my deployment time from 6 minutes to 9.6 seconds.

I’ve been practicing semi-continuous deployments on Chirk HR since I’ve started (where I am deploying to production as soon as code is useful). I’ve been having a problem with the asset pipeline though because the assets:precompile task is taking minutes to run. Slow deployments lead to me not deploying as often, which caused a bunch of pain and slower feedback.

Part of this is because Rails generates assets twice, once for the digest version (/assets/application-2d25da195f64bf181b34b5d15972cca6.js) and once for the non-digest version (/assets/application.js). A tip I heard from Jeremy Kemper was to only use the primary version which will skip the non-digest compilation.

After a bit of searching, I came across another idea. Ben Curtis posted a capistranio task that will use git to see if your assets have changed and skip regenerating them if they haven’t changed.

This is huge boost for Chirk’s continous deployment since the majority of my changes aren’t asset related at all.

Tip: If after adding this change and deploying if you see that assets are still getting compiled, check your Capfile to make sure you are loading config/deploy after deploy/assets. Otherwise your custom precompile task in config/deploy is getting overrided by cap’s default task in deploy/assets. From Stackoverflow

About Eric Davis

I founded Little Stream Software where I help new entrepreneurs build a successful software business. I also created an ebook, Redmine Tips, where I show you how to become more productive using Redmine. I am also the author of Refactoring Redmine, where I go about refactoring Rails using Redmine as an example. Follow me on Twitter and Google Plus.

, , , ,

2 Responses to Speeding up Capistrano Deployments from 6 Minutes to 9 Seconds by Skipping Asset Compilation

  1. vitomd June 10, 2012 at 7:25 am #

    That’s fast, thanks for the tip. Good look with Chirk it’s look great.

  2. Rohit Mishra December 26, 2012 at 12:17 pm #

    The best solution I found is https://github.com/ndbroadbent/turbo-sprockets-rails3 which ensures that only those assets which have changed are recompiled.

Leave a Reply