Bulk Yui compressor script

We’ve been using JSMin for our JavaScript minification purposes.

As I’m currently tasked to improve our website’s initial loading performance by more than 50%, I started looking at also minifiying CSS files.

I read up on Yui Compressor, because it allows you to minify CSS. I read that it also results in smaller JS minified files than other minification strategies, and gave it a go on our JS files. I wasn’t disappointed, it gave us 10% reduction in size than with JSMin.  

Seeing that we’ve got a hell of a lot of JS libraries in our site, I came up with a strategy to bulk minify all our JS files in one go as part of our build process.

I’ve been burning to do some PowerShellscripting again, so I developed a script which minifies all our JS and CSS files. You’ll have to be familiar with PowerShell, and if you aren’t why not?! You’ll also have to change the paths to match your environment.

$yuiPath = “..\lib\Repository\YahooUI\yuicompressor-2.4.2\build\yuicompressor-2.4.2.jar”

$scriptFiles = Get-ChildItem “..\OlrWebApp2\scripts” -r
foreach($file in $scriptFiles)
{
    Write-Host(“MINIMIZING ” + $file.fullname)
    $targetFile = $file.fullname -replace(“.js”, “_min.js”);
    java -jar $yuiPath $file.fullname -o $targetFile
}

$stylesheets = Get-ChildItem “..\OlrWebApp2\Branding\cpu” -r -include *.css
foreach($file in $stylesheets)
{
    Write-Host(“MINIMIZING ” + $file.fullname)
    $targetFile = $file.fullname -replace(“.css”, “_min.css”);
    java -jar $yuiPath $file.fullname -o $targetFile
}

Write-Host(“Done”)
$null = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)

Advertisements

~ by hendrikswan on June 5, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: