How to Compress JavaScript using YUI Compressor

Leave a Comment

Yahoo’s JavaScript compressor, YUI Compressor, lives at http://developer.yahoo.com/yui/compressor.

How to Compress JavaScript

Launch a web browser and visit http://www.refresh-sf.com/yui/.

Click the File(s) link.

Alternatively, you can just copy the JavaScript code from your text editor and paste it into the large text box at the site’s homepage.

Click the Choose File button and locate the external JavaScript file on your computer.

Click the Choose File button and locate the external JavaScript file on your computer.

The file must contain only JavaScript. For example, you can’t select a HTML file that also has JavaScript programming in it.

Yahoo’s JavaScript compressor, YUI Compressor.

Select the “Redirect to gzipped output” box (just above the Compress button).

This option lets you download the minimized code in a new, zipped file. This will be your new, compressed, external JavaScript file, which you can save to your site.

Click the Compress button.

The website processes your code and downloads the compressed file to your computer. You can then rename this file (since it’s always saved as min.js), and put it into your site for use.

The Online YUI Compressor site provides a nice report after you compress a file, listing the original file size, the new, compressed file size, and a percentage that represents how much smaller the new file is.

0 comments:

Post a Comment