-
-
Save dtuite/9fc8c1837837dbd11d0d to your computer and use it in GitHub Desktop.
Gzip assets when deploying with capistrano and Rails 4.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/assets.rake | |
namespace :assets do | |
task :gzip do | |
require 'zlib' | |
Dir['public/assets/**/*.{js,css}'].each do |path| | |
gz_path = "#{path}.gz" | |
next if File.exist?(gz_path) | |
Zlib::GzipWriter.open(gz_path) do |gz| | |
gz.mtime = File.mtime(path) | |
gz.orig_name = path | |
gz.write(IO.binread(path)) | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/capistrano/tasks/assets.rake | |
namespace :deploy do | |
namespace :assets do | |
task :gzip do | |
on roles(:web) do | |
within release_path do | |
execute :bundle, 'exec rake assets:gzip RAILS_ENV=production' | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/deploy.rb | |
after 'deploy:assets:precompile', 'deploy:assets:gzip' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment