Skip to content

Instantly share code, notes, and snippets.

@piouPiouM
Forked from Palleas/gist:455656
Created June 28, 2010 10:11
Show Gist options
  • Save piouPiouM/455665 to your computer and use it in GitHub Desktop.
Save piouPiouM/455665 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(
'js_code' => file_get_contents($argv[1]),
'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
'output_format' => 'json',
'output_info' => 'compiled_code',
);
$ctx = stream_context_create(array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($args)
)
));
$response = file_get_contents(GATEWAY, false, $ctx);
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