Created
June 27, 2015 03:02
-
-
Save leomao/bd6a97d7ad0028a1da2b to your computer and use it in GitHub Desktop.
optimize javascript using 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
#! /usr/bin/env python3 | |
import http.client, urllib.parse, sys | |
# Define the parameters for the POST request and encode them in | |
# a URL-safe format. | |
params = urllib.parse.urlencode([ | |
('js_code', sys.argv[1]), | |
('compilation_level', 'SIMPLE_OPTIMIZATIONS'), | |
('output_format', 'text'), | |
('output_info', 'compiled_code'), | |
]) | |
# Always use the following value for the Content-type header. | |
headers = { "Content-type": "application/x-www-form-urlencoded" } | |
conn = http.client.HTTPConnection('closure-compiler.appspot.com') | |
conn.request('POST', '/compile', params, headers) | |
response = conn.getresponse() | |
data = response.read() | |
print(data) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment