Run Microsoft Ajax Minifier from the Visual Studio Tools Menu

Microsoft have created a great tool, Ajax Minifier a free tool that you can use to minify your JavaScript and Cascading Style Sheet files. So far I have had no problems with the minified JavaScript. I have tried a few other tools which worked most of the time but not always.

The documentation is very good with plenty of examples and also including information on how to use the Microsoft Ajax Minifier as a Build Task  so that every time you perform a build in a Visual Studio ASP.NET project, you can minify all of your JavaScript and Cascading Style Sheet files automatically.

I wanted to run the program on individual files experimenting with the options. For this I preferred to integrate the Microsoft Ajax Minifier into the Visual Studio Tools menu. I wanted the Ajax Minifier to run against the file I currently had open and save the output as a copy in the format of filename.min.extension, for example Common.js gets saved a Common.min.js.
 



Command: C:\Program Files\Microsoft\Microsoft Ajax Minifier\AjaxMin.exe

Argument: $(ItemFileName)$(ItemExt)  -clobber -out $(ItemFileName).min$(ItemExt)

Initial Directory: $(ItemDir)

By ticking use output window you can see some minification stats or any problems if the program fails to execute. You will need to show all files to see the newly created file in the solution explorer. Using the -clobber option overwrites any existing file with the same file name so be careful you have -out argument correct.

I found this quite useful as I didn't want to minifiy everything in the project and typing in the command line each time would quickly become a drag.


Comments
Shekhar Tuesday December 21 2010 03:26 p.m.
This is a great tip. Would be helpful for me.