Google Closure Compiler with PHP
Now i show you how to use the new Google Closure Compiler over the RESTful API with PHP5. First of all, you don’t need to install anything, we will connect the free API via cURL usually activated in PHP5.
The API (see reference) resides under the following URL and requires four params:
enough with theory, now the PHP code:
$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);
i use it in a deployer script and replace the content of my script files with the compiled versions. you can tryout the compiler with a simple html-form.