Go to the documentation of this file.00001
00002
00003 import httplib, urllib, sys
00004 import time
00005
00006
00007
00008 def minimize(code):
00009
00010 params = urllib.urlencode([
00011 ('js_code', code),
00012 ('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
00013 ('output_format', 'text'),
00014 ('output_info', 'compiled_code'),
00015 ])
00016
00017 t = time.time()
00018
00019 headers = { "Content-type": "application/x-www-form-urlencoded" }
00020 conn = httplib.HTTPConnection('closure-compiler.appspot.com')
00021 conn.request('POST', '/compile', params, headers)
00022 response = conn.getresponse()
00023 data = response.read()
00024 conn.close()
00025 if data.startswith("Error"):
00026 raise Exception(data)
00027 print "%.3f seconds to compile" % (time.time() - t)
00028 return data