Skip to content

Instantly share code, notes, and snippets.

@sunilmallya
Created March 5, 2015 21:08
Show Gist options
  • Save sunilmallya/a7a894b3df29649289ae to your computer and use it in GitHub Desktop.
Save sunilmallya/a7a894b3df29649289ae to your computer and use it in GitHub Desktop.
Compiling js online with closure
import urllib
import urllib2
CLOSURE_URL = "http://closure-compiler.appspot.com/compile"
def compile_js(contents):
data = { "compilation_level" : "SIMPLE_OPTIMIZATIONS",
"output_format" : "text",
"output_info" : "compiled_code",
"js_code" : contents
}
body = urllib.urlencode(data)
req = urllib2.Request(CLOSURE_URL, body)
try:
response = urllib2.urlopen(req)
output = response.read()
return output
except Exception, e:
print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment