Thursday, September 9, 2010

Javascript Compression

If your using alot of Javascript and/or CSS in your applications, and want to keep it as compact as possible, you might want to check out yuicompressor (Java Application).
http://developer.yahoo.com/yui/compressor/

to run it with a .bat file (modify file locations - basically compressing original style.css to the css_c compressed folder.):
java -jar yuicompressor-2.3.5.jar --line-break 0 --nomunge D:\www\xampp\htdocs\web\css\style.css -o D:\www\xampp\htdocs\web\css_c\style.css

In php you can then just toggle the original code and compressed code with something like:
if($debugg) {
$siteJsDir = $siteWebDir . "/js_c";
$siteCssDir = $siteWebDir . "/css_c";
} else {
$siteJsDir = $siteWebDir . "/js";
$siteCssDir = $siteWebDir . "/css";
}

then include it in web page
echo "link href=$siteCssDir/style.css  .......................

No comments:

Post a Comment