Installing YUI Compressor
Yahoo has created an often and well proved compressor which we are going to use. Download the latest version from this page: http://yuilibrary.com/download/yuicompressor/. If you extract the file, you’ll see a bunch of directories and files, but only the one in the build directory is actually required. Move the yuicompressor-x.y.z.jar into a directory of your choice. I used C:\Program Files\YuiCompressor as I thought it’s kind of an application and belongs in the program files, but feel free to use any other directory.
Creating Batch File to call Yui Compressor
We are going to create a small little wrapper which will call the YUI compressor. For this, create a new file called compress.bat in the same directory. Mine looks like this:
In this file, add the following content:
java -jar "%~dp0\yuicompressor-2.4.7.jar" %1 -o %~n1.min%~x1
Make sure you are using the correct version (2.4.7 at the time of writing). As you can also see, the YUI Compressor uses Java. If it’s not already installed, install either the Java JRE or Java SDK http://java.com/en/download/index.jsp.
Adding Shell Extension
We need some new registry entries to call our wrapper directly from the Windows explorer. Hit “Windows + R” and enter “regedit” to open the registry editor. Please note: Changes in the registry editor have to be done very carefully! Doing the wrong changes in the registry can break your Windows installation!
In the left pane, select HKEY_CLASSES_ROOT\.js and look for the value in the right pane. The value we need is JSFile in the following screenshot:
In HKEY_CLASSES_ROOT we have to find the value we just found. In that folder you should find another key called “shell”.
- Right click on “shell”
- Select “New – Key”
- Enter “compress” and confirm it
- Select the newly created key
- Open the default value on the right and enter “Compress”
- Right click on the new folder “compress” in the right panel and select “New – Key”
- Enter “Command” and enter the following value: “”C:\Program Files\YuiCompressor\compress.bat” “%1″”
Adjust the path in the last step according to the directory where you installed the YUI compressor.
If you’re done, you should have the following structure: