Download the application here

Recently the the Microsoft AJAX team released Ajax Preview 6 up on codeplex (Check it out here). With this release they also released an Ajax Minifier tool that will allow you to crunch or minify JS files. There are several ways to use the minifier tool, you can incorporate in into your build process using msbuild, you could run command line tool manually and create an output file, or you can use the minifier dll that gets distributed with the tool in your own applications. It is this third option that sparked my interest so I thought I would whip an application that allows you to load Javascript into an editor and then “crunch” it with the Ajax minifier object and visually see the output. Below is a screen shot of the final output. (I am adding a settings option so you can control how the minifier works)

 

image

If you just want to grab the zip fie that has the exe in it to run, you can grab it from here.

The first thing we will need to do is grab and install the Ajax Minifier from here. Once installed you will find the ajaxmin.dll file in the install location, like the following. It is that file that contains all the “crunching” code and the file you will need to reference in your project.

image

Once you have referenced the ajaxmin.dll file in your solution you will be able to “crunch” some javascript. In order to “crunch” the javascript you will need to make a call like the following.

Code Snippet
  1.                 string Js = @"function ()
  2. {
  3.     //these are some javascript comments
  4.     var testVar = 'this is some alert text';
  5.     alert('Hey What are you doing!!!!, Crunch this stuff.....');
  6. }";
  7.                 Microsoft.Ajax.Utilities.ScriptCruncher sc = new Microsoft.Ajax.Utilities.ScriptCruncher();
  8.                 string CrunchedJS = sc.Crunch(Js);

 

I also want to give credit to the #develop guys over at ic#code for putting out a excellent open source IDE for .NET development. I am using the #develop’s  code editor control in this project to obtain the syntax highlighting, etc. Great work guys!!

you can check them out over at http://www.icsharpcode.net/OpenSource/SD/

 

That’s it for now and as always if you have any comments or questions you can comment here at the blog or catch me on twitter at http://twitter.com/johnmcbride