Google Closure Compiler with PHP
2009-11-12 10:36
393 查看
Today Google released their new Closure Compiler
, you can use it to optimize and minify your javascripts.
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:
http://closure-compiler.appspot.com/compile
enough with theory, now the PHP code:
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
, you can use it to optimize and minify your javascripts.
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:
http://closure-compiler.appspot.com/compile
compilation_level is one of three options: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS, i use simple optimizations, it don't need further config (like advanced) but is better than whitespace only. output_format is "text" if you want compile a javascript output_info is "compiled_code" if you want compile a javascript js_code is your javascript source code, instead you can submit "code_url" param, an url to a javascript-file
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
相关文章推荐
- Google的js压缩与优化工具: Getting Started with the Closure Compiler Application
- 使用Google Closure Compiler高级压缩Javascript代码
- js 压缩工具 google closure compiler
- http://www.ajaxlines.com/ajax/stuff/article/using_google_is_ajax_search_api_with_java.php
- 使用Google closure Compiler 压缩javascript文件
- 使用Google Closure Compiler全力压缩代码(转)
- Google Closure Compiler 高级模式及更多思考(转)
- 使用eval导致Google Closure Compiler压缩代码后运行出错的解决办法
- 在项目中使用Google Closure Compiler
- [How-To]如何使用GNU Make 简化Google Closure Compiler的使用
- 转:在项目中使用Google Closure Compiler(js压缩)
- Google Closure Compiler开源的javascript压缩加密工具
- 在项目中使用Google Closure Compiler
- Google Merchant How To Setup A Live XML Data Feed With MySql and PHP
- Beginning Google Maps Applications with PHP and Ajax: From Novice to Professional
- Professional Web APIs with PHP: eBay, Google, Paypal, Amazon, FedEx plus Web Feeds
- 使用Google Closure Compiler高级压缩Javascript代码注意的几个地方
- 使用Google JavaScript Closure Compiler压缩 javascript 文件
- 在线压缩javascript --- Google Closure Compiler
- JavaScript Compiler Power by Google Closure Tools