[OpenLayers-Commits] r11443 - in trunk/openlayers: build tools

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Feb 24 17:39:40 EST 2011


Author: crschmidt
Date: 2011-02-24 14:39:40 -0800 (Thu, 24 Feb 2011)
New Revision: 11443

Added:
   trunk/openlayers/tools/closure_ws.py
Modified:
   trunk/openlayers/build/build.py
Log:
Add support for the closure compiler webservice, using simple optimizations.
Using this build mode, on a lite build, we save approximately 15% after
gzip. However, this build method can not be used on full builds, as they
exceed the 1000kb limit on the closure compiler webservice. 


Modified: trunk/openlayers/build/build.py
===================================================================
--- trunk/openlayers/build/build.py	2011-02-24 17:34:37 UTC (rev 11442)
+++ trunk/openlayers/build/build.py	2011-02-24 22:39:40 UTC (rev 11443)
@@ -12,6 +12,11 @@
         have_compressor.append("jsmin")
     except ImportError:
         print "No jsmin"
+    try:
+        import closure_ws
+        have_compressor.append("closure_ws")
+    except ImportError:
+        print "No closure_ws"
     
     try:
         import minimize
@@ -39,14 +44,14 @@
 
     print "Merging libraries."
     merged = mergejs.run(sourceDirectory, None, configFilename)
+    print "Compressing using %s" % use_compressor
     if use_compressor == "jsmin":
-        print "Compressing using jsmin."
         minimized = jsmin.jsmin(merged)
     elif use_compressor == "minimize":
-        print "Compressing using minimize."
         minimized = minimize.minimize(merged)
+    elif use_compressor == "closure_ws":
+        minimized = closure_ws.minimize(merged)      
     else: # fallback
-        print "Not compressing."
         minimized = merged 
     print "Adding license file."
     minimized = file("license.txt").read() + minimized

Added: trunk/openlayers/tools/closure_ws.py
===================================================================
--- trunk/openlayers/tools/closure_ws.py	                        (rev 0)
+++ trunk/openlayers/tools/closure_ws.py	2011-02-24 22:39:40 UTC (rev 11443)
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+
+import httplib, urllib, sys
+import time
+# Define the parameters for the POST request and encode them in
+# a URL-safe format.
+
+def minimize(code):
+
+    params = urllib.urlencode([
+        ('js_code', code),
+        ('compilation_level', 'SIMPLE_OPTIMIZATIONS'),
+        ('output_format', 'text'),
+        ('output_info', 'compiled_code'),
+      ])
+    
+    t = time.time()
+    # Always use the following value for the Content-type header.
+    headers = { "Content-type": "application/x-www-form-urlencoded" }
+    conn = httplib.HTTPConnection('closure-compiler.appspot.com')
+    conn.request('POST', '/compile', params, headers)
+    response = conn.getresponse()
+    data = response.read()
+    conn.close()
+    print "%.3f seconds to compile", time.time() - t 
+    return data



More information about the Commits mailing list