Permalink
Browse files

Prevent gzip files from being gratuitously different.

By default, mtime is 0 and in that case, Zlib will set it to Time.now,
and each time the same uncompressed file is compressed, the output will
be different. So I chose another integer, 1 seemed nice, but any would
do, it just needs to be the same every time.
  • Loading branch information...
1 parent 37e0b4f commit 5bca24e9e59b94fc68d74bd88d0821a4810c74af @mat813 mat813 committed Apr 25, 2012
Showing with 2 additions and 0 deletions.
  1. +1 −0 lib/sprockets/asset.rb
  2. +1 −0 lib/sprockets/static_asset.rb
View
1 lib/sprockets/asset.rb
@@ -145,6 +145,7 @@ def write_to(filename, options = {})
if options[:compress]
# Run contents through `Zlib`
gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
+ gz.mtime = 1
gz.write to_s
gz.close
else
View
1 lib/sprockets/static_asset.rb
@@ -30,6 +30,7 @@ def write_to(filename, options = {})
pathname.open('rb') do |rd|
File.open("#{filename}+", 'wb') do |wr|
gz = Zlib::GzipWriter.new(wr, Zlib::BEST_COMPRESSION)
+ gz.mtime = 1
buf = ""
while rd.read(16384, buf)
gz.write(buf)

0 comments on commit 5bca24e

Please sign in to comment.