>
 



Recently, I have written a C# wrapper for Google Closure Compiler to use with ASP.NET for on-the-fly JavaScript compression. For those who want to use the Closure Compiler with PHP, Bohuco.net has an article showing how to use the Google Closure Compiler over its RESTful API with PHP5.  

$script = file_get_contents('http://www.domain.com/scripts/script.js');
$ch = curl_init('http://closure-compiler.appspot.com/compile');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'output_info=compiled_code&output_format=text&compilation_level=SIMPLE_OPTIMIZATIONS&js_code=' . urlencode($script));
$output = curl_exec($ch);
curl_close($ch);

You can find more details on using Closure Compiler with PHP 5 here.

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5



On November 5th, Google released Closure Compiler for Javascript optimization. The strongest part of the Closure Compiler is that it does not only remove whitespace but also rewrites Javascript Code to make it smaller. It also optimizes your Javascript code to perform better. You can find more details and all of its features on my previous article: Closure Compiler – Javascript Compiler by Google.

During my tests, Closure Compiler reduced Javascripts more than 60%. Considering, the size of Javascript files that modern websites have and the reduction before HTTP compression, Closure Compiler is really useful. 

Closure Compiler comes with a Java based command line tool and a RESTful API.  RESTful API works great and very fast. API can be used with a MSBuild or NAnt script to automatically compress Javascript files.

I wrote a C# wrapper for the Google Closure Compiler:

Google's Javascript compressor - C# wrapper
C# wrapper for the Google Closure Compiler

 

More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5