PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

SitePoint PHP Blog: How to Roll Your Own JavaScript Compressor with PHP and the Closure Compiler

Note: This article was originally published at PHPDeveloper on 1 September 2010.
PHPDeveloper

On the SitePoint PHP blog today there's a quick new post showing you how to create a Javascript compressor tool with PHP that uses the Closure Compiler from Google.

In my previous post, I discussed the Closure Compiler's REST API. In this article, we'll develop a small PHP program that shows how the API can be used to compress JavaScript code whenever you need it.

He shows how to compress three "script" tags down into one that defines multiple files for the engine to grab and compress. This is passed into a PHP file that grabs the file and passes the data off to the Closure Compiler for handling (via curl). The result is then passed back and served up with a content type of "text/javascript" back to the browser.