The first step is download the YUI Compressor and put it somewhere handy. I put it directly in the
c: directory for easy access. Then, I created a simple batch file called
compress.bat and also placed it in
c: for each access. The content of the batch file are as follows:
java -jar c:yuicompressor-2.1.2.jar %1
This line essentially runs the YUI Compressor against a file that is specified as the first command-line argument (
%1). You can now simply type the following into a command window:
To take this one step further, you can add a “Compress” context menu item. To do so, follow these steps:
- Open an Explorer window.
- Under the Tools menu, click Folder Options.
- Click on the File Types tab.
- In the list, select “JS” and click the Advanced button.
- Click the New… button.
- In the Action field, type “Compress”.
- In the Application used to perform field, type “c:compress.bat “%1″”.
- Click OK.
- Click OK again.
- Click Close.
Once that is done, you can right-click on any file ending with a .js extension and see a context menu item called “Compress”. When clicked, the command runs the YUI Compressor and the output is placed in the same directory.
I’ve found this to be a very handy way to use the YUI Compressor. I hope it’s equally as useful for you.