Created
August 18, 2010 15:45
-
-
Save fxn/535191 to your computer and use it in GitHub Desktop.
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
| #!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks :)