Capistrano has a great way that runs rake assets:precompile for you when you are deploying your Rails app. And you get one css file and one javascript file to load per request without worrying about assets not showing up once you deploy your app.

That said, the precompiling during deployment may take up a huge amount of time and may overload your server (if its a smaller VPS).

Because Capistrano creates a symlink for the assets that is moved across deployments, sometimes its really not necessary to compile the assets especially when your app's asset files remain the same (meaning no addition or deletion of images/css/js files etc).

To circumvent the default Capistrano setting which compiles the assets during each deployment, regardless of whether any assets were changed in the set of commits, you can compile the assets only if assets show up in that list. And here is how you can do it by adding the code snippet below to your deploy.rb:

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
  end
end