How can I make Rails 3 assets precompile faster? How can I make Rails 3 assets precompile faster? ruby ruby

How can I make Rails 3 assets precompile faster?


This isn't an answer on making it run faster, but as far as a "different procedure" goes, you can tell Capistrano to only precompile assets when you've actually made any changes to your assets. You would want to do a custom assets:precompile task something like this, which would look at the git logs between the existing and newly deployed code. For me, this worked great and now I only need to deal with slow deployment when updating assets:

namespace :deploy do  namespace :assets do    task :precompile, :roles => :web, :except => { :no_release => true } do      from = source.next_revision(current_revision)      if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0        run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}      else        logger.info "Skipping asset pre-compilation because there were no asset changes"      end    end  endend

Source: http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano/


I've just written a gem to solve this problem inside Rails, called turbo-sprockets-rails3. It speeds up your assets:precompile by only recompiling changed files, and only compiling once to generate all assets. It works out of the box for Capistrano, since your assets directory is shared between releases.

It would be awesome if you could help me test out the turbo-sprockets-rails3 gem, and let me know if you have any problems.