Created
July 4, 2011 16:33
-
-
Save danmayer/1063584 to your computer and use it in GitHub Desktop.
Compress a collection of js files with closure compiler
This file contains 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
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