Compress JavaScript to speed up download : The online compressor for YUI

When building AJAX dynamic web applications you’ll have to load lots of JavaScript libraries, one of them will be the YUI, (Yahoo UI), which has a whole bunch of handy library components that you can use for Ajax and DHTML web apps.

But using the YUI will need you to include a huge JS file, which may take some significant times to download to the client machine. Therefore, it’s a wise choice to shorten the file or to compress it using web gzip compression or to compress it by removing all the unecessary white space and the new line characters (\n)

If you got NO clue on how to shorten or compress a YUI library JS file, Rodolphe Stoclin has got an online compressor for the YUI lib, which is a great helper to reduce the file size of your YUI library. Just upload your YUI JS file, and it’ll return a compressed version for you to use. And it also shows the compression rate on the fly.

Some other method to compress an overly big Javascript file for easier download, is to convert it into PHP, and using the PHP ob_start function for the compression, such as follows:

<?php
/**
The function used to remove all the \n , but you must ensure each statement in your JS file terminates properly with ; or else this may give some problems by having removed the \n
*/

function flatcode($buffer,$mode)
{
return ob_gzhandler(str_replace(“\n”, “”,$buffer),$mode);
}
ob_start( ‘flatcode’ );
header(‘Content-type:text/javascript’);
?>
// Copy and paste all the JavaScript file here
<?php ob_end_flush();?>

By Ajaxapp.com

Enter your email address to subscribe our newsletter or feed for FREE:

Delivered by FeedBurner


Bookmark with:

[Delicious]    [Digg]    [Reddit]    [Facebook]    [StumbleUpon]

0 Responses to “Compress JavaScript to speed up download : The online compressor for YUI”


  1. No Comments

Leave a Reply

You must login to post a comment.