Created
March 5, 2015 21:08
-
-
Save sunilmallya/a7a894b3df29649289ae to your computer and use it in GitHub Desktop.
Compiling js online with closure
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
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