Skip to content

Instantly share code, notes, and snippets.

@danmayer
Created July 4, 2011 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmayer/1063584 to your computer and use it in GitHub Desktop.
Save danmayer/1063584 to your computer and use it in GitHub Desktop.
Compress a collection of js files with closure compiler
require 'net/http'
require 'uri'
COMPRESS_LEVEL = "SIMPLE_OPTIMIZATIONS"
FILE_PATH = "assets/www/"
FILES = ['application','custom','plugin','base']
def compress(compilation_level,jscode)
response = Net::HTTP.post_form(URI.parse('http://closure-compiler.appspot.com/compile'), {
'js_code' => jscode,
'compilation_level' => "#{compilation_level}",
'output_format' => 'text',
'output_info' => 'compiled_code'
})
response.body
end
FILES.each do |f|
filename = FILE_PATH + f + ".js"
compressed_filename = FILE_PATH + f + ".min.js"
content = File.read(filename)
result = compress(COMPRESS_LEVEL, content)
File.open(compressed_filename, 'w') {|f| f.write(result) }
end
puts "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment