Skip to content

Instantly share code, notes, and snippets.

@fxn
Created August 18, 2010 15:45
Show Gist options
  • Save fxn/535191 to your computer and use it in GitHub Desktop.
Save fxn/535191 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# A simple script to gzip content recursively. I use it for the Nginx gzip_static module.
require 'find'
EXTENSIONS = %w(.js .html .css)
def gzname(file)
"#{file}.gz"
end
def compress(file)
puts "compressing #{file}"
system %(gzip -c -9 "#{file}" > "#{gzname(file)}")
end
def compress?(file)
if EXTENSIONS.include?(File.extname(file))
!File.exists?(gzname(file)) || File.mtime(gzname(file)) < File.mtime(file)
end
end
ARGV.each do |dir|
Find.find(dir) do |file|
compress(file) if compress?(file)
end
end
@yury
Copy link

yury commented Aug 18, 2010

thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment