local_asset_precompile
⚙️ Local Asset Precompilation for Faster Deploys
Precompiling assets on your local machine can drastically reduce deploy times and server load. By generating the compiled files locally and uploading them, you avoid spending precious seconds on each web server. Add a custom task in config/deploy.rb
to run the assets:precompile
rake task locally and sync the output to your release.
# config/deploy.rb
namespace :deploy do
desc 'Precompile assets locally and upload to servers'
task :compile_assets_locally do
run_locally { execute 'RAILS_ENV=production bundle exec rake assets:precompile' }
on roles(:web) do
upload!('public/assets/', "#{release_path}/public/assets/", recursive: true)
end
run_locally { execute 'rm -rf public/assets' }
end
before :updated, 'deploy:compile_assets_locally'
end