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
deploy/assets. Otherwise your custom precompile task in
config/deploy is getting overrided by cap’s default task in
deploy/assets. From Stackoverflow
[button size=”large” color=”#009DDC” style=”download” link=”http://theadmin.org/capistrano-variables-download”]Download a list of every capistrano variable[/button]