Compress context menu item for Windows XP
Just thought I’d share a quick tip. I’m one of the few developers I know who uses Windows almost exclusively (sorry, no Mac here). Lately, I’ve been wanting to see how my JavaScript files would be compressed using Julien’s YUI Compressor. Previously, I was keeping a command window open and typing the command in directly. I figured there must be a simpler way to do this, and I was right.
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:
c:>compress.bat myfile.js
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.
Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.