PHP, JS and CSS Compression

I wasn’t feeling very well today, so I thought I’d do something more light-hearted and fun.

Yes, that’s right! I wrote a website compression utility!

Basically, you do “php sitecompress.php mywebsitefolder” and it goes through all the .php, .html, .htm, .js and .css files. Javascript and CSS (inline and external – yes I said inline. It pulls out the scripts and styles embedded in your HTML and compresses those too) go through YUICompressor (courtesy of Yahoo UI library), PHP and HTML go through an internal algorithm to kill the whitespace. No, I didn’t use “php -w filename”, that would (a) be cheating, and (b) not be very good. Seems PHP’s own whitespace removal is a bit lackluster and keeps a lot of unnecessary whitespace.

I’ve run it on a download of microsoft.com and it displays identically. I’ve run it on the source code of PHPBB3 (after realising I have to add a “keep html comments” option, due to their templating system) and that seems fine (strips 4mb off the 37mb install).

I’ll do a bit more testing in the next couple of days and GPL it on Lamped.co.uk.

p.s. Apologies for the poor readability, It’s 00:45 and I’m very tired…

This entry was posted on Sunday, July 26th, 2009 at 23:46 and is filed under Javascript, PHP. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.