php - Google Closure, Response Always Empty -
i'm trying basic example of how use google closure minify js. can't seem work @ all.
i'm trying follow these examples:
https://developers.google.com/closure/compiler/docs/gettingstarted_api http://closure-compiler.appspot.com/home
when working on api's and/or ajax code, first thing try variables , values setup using advanced rest client applications - chrome extension. whenever send data, though, empty response (image below).
trying insert same code php code, no matter send in $postdata variable, empty (null) response.
php code:
$postdata = http_build_query( [ 'output_info' => 'compiled_code', 'output_format' => 'text', 'compilation_level' => 'simple_optimizations', 'js_code' => urlencode("function hello(name) { // greets user alert('hello, ' + name); } hello('new user');") ] ); $ret = $this->ci->curl->simple_post( $url, $postdata, $options ); var_dump($ret); die();
response:
string ' ' (length=1)
i'm 99% confident i'm missing use closure api key or something, have no idea how proceed.
after many, many, many attempts, found if used rawurlencode() instead of urlencode(), works. here's final function.
// use google closure compiled js $encoded = rawurlencode($js); $postdata = 'output_info=compiled_code&' . 'output_format=text&' . 'compilation_level=whitespace_only&' . 'js_code=' . $encoded ; $options = []; $call = curl_init(); curl_setopt_array( $call, array( curlopt_url => 'http://closure-compiler.appspot.com/compile', curlopt_post => 1, curlopt_postfields => $postdata, curlopt_returntransfer => 1, curlopt_header => 0, curlopt_followlocation => 0 ) ); $jscomp = curl_exec($call); return $jscomp;
Comments
Post a Comment