Skip to content

Instantly share code, notes, and snippets.

@Palleas
Created June 28, 2010 09:58
Show Gist options
  • Save Palleas/455656 to your computer and use it in GitHub Desktop.
Save Palleas/455656 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
define('FILENAME', 'core.min.js');
define('GATEWAY', 'http://closure-compiler.appspot.com/compile');
$args = array();
$args['js_code'] = file_get_contents($argv[1]);
$args['compilation_level'] = 'SIMPLE_OPTIMIZATIONS';
$args['output_format'] = 'json';
$args['output_info'] = 'compiled_code';
$handler = curl_init();
curl_setopt($handler, CURLOPT_URL, GATEWAY);
curl_setopt($handler, CURLOPT_POST, true);
curl_setopt($handler, CURLOPT_POSTFIELDS, http_build_query($args));
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handler);
if (false === $response)
echo "An error occured while trying to compress javascript source !\n";
else
{
$responseObject = json_decode($response);
file_put_contents(FILENAME, $responseObject->compiledCode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment