How do I enable gzip file generation in Rails 4.2?
As of April 14, 2015, it looks like .gz
file compilation has been removed from asterisks in the latest version of Rails.
https://github.com/rails/sprockets/issues/26
I used these files on S3 server to speed up page loading, but since the compilation of gzip files was removed on the specified stream, I have a big question. If you are using a host resource, what is the new solution for compiling files .gz
? If I were working with files from my server, it would be relatively easy, but the static assets were placed elsewhere and needed to be compiled first.
Anyway, I hope someone figured it out. My workaround, if I can't get the asset pipeline to build and download files .gz
as I once did, is to manually create them using grunt-contrib-compress ( https://github.com/gruntjs/grunt-contrib-compress ) ... But, as we all know, manual solutions don't scale very well, and I'd rather have the asset pipeline take care of this during deployment.
Many thanks for the help.:)
source to share
Since Rake does not override but sets chains, you can declare another one assets:precompile
. The following solution should work without changing your deployment scripts:
#/lib/tasks/assets.rake
namespace :assets do
# We make use of rake behaviour and chain this after rails' assets:precompile.
desc 'Gzip assets after rails has finished precompilation'
task :precompile do
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
source to share