Skip to content

Instantly share code, notes, and snippets.

@leomao
Created June 27, 2015 03:02
Show Gist options
  • Save leomao/bd6a97d7ad0028a1da2b to your computer and use it in GitHub Desktop.
Save leomao/bd6a97d7ad0028a1da2b to your computer and use it in GitHub Desktop.
optimize javascript using closure compiler
#! /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