Getting Started
Using Microsoft Ajax Minifier is easy: simply specify one or more input source files on the command line, and the minified output will be sent to the STDOUT stream:
ajaxmin.exe sourcefile.js
 
If you’d like to automatically save the minified output to a file, use the –out switch and specify the output path. If the file already exists, the file will not be overwritten unless the –clobber switch is used:
ajaxmin.exe sourcefile.js –out outputfile.js –clobber
 
If you would like to analyze your script for possible bugs, use the -analyze option:
ajaxmin.exe sourcefile.js –analyze
 
Microsoft Ajax Minifier will minify both JavaScript and CSS Stylesheets, but do not mix the file types in a single instantiation. Use the –CSS or –JS options if the STDIN is used as input (no input files specified) or if the input files don’t have the standard .JS or .CSS file extensions.
 
To combine multiple input files into a single output file, simply specify multiple input files on the command-line:
ajaxmin.exe source1.js source2.js source3.js –out outputfile.js
 
To make your output not be all on a single line (the default behavior), there are two options:
  1. use the –line switch to output in multiple-line format if you are making any changes to the input code, such as renaming local variables and functions, stripping out debug statements, or any other formatting beyond whitespace and comments; or
  2. use the –pretty switch if (and only if) you are making no changes to the input code, but just want to make it easier to read by adding whitespace.
The –line switch has a number of options: an optional target line-length after which a new line will be started at the next available spot, an optional multiple-line vs single-line indicator, and an optional number of spaces to use for a single indention when in multiple-line format (default is 4). Although all three options are technically optional, at least one must be specified; all three can be specified at the same time if so desired. For example, to make your output be in multiple-line format with the default 4-space indention level:
ajaxmin sourcefile.js –out outputfile.js -line:M
To make your minified output be on multiple lines with an 8-space indention level, use:
ajaxmin sourcefile.js –out outputfile.js -line:M,8
To make your minified output line-break after 200 characters so it’s not all on a single line, but otherwise compacted, use:
ajaxmin sourcefile.js –out outputfile.js -line:200
 

Text Encoding
It is a frequently-reported “issue” that extended characters (non-ASCII) sometimes get “mangled” in the AjaxMin output. This is not an issue with AjaxMin, but rather a mismatch in text encodings between build processes and/or the server. Please see this FAQ entry on text encoding for more information. AjaxMin outputs UTF-8 with no BOM by default, which requires no explicit escaping of any UNICODE source character. If there is a mismatch anywhere in your system, it may be prudent to change to the ASCII encoding output via the –enc:out switch.
 
More Information:
 
 
After running the MSI, the installed files will be:
 
<programfiles>\Microsoft\Microsoft Ajax Minifier
    • AjaxMin.exe
    • AjaxMinifier.exe
    • AjaxMin.dll
    • AjaxMinTask.dll
    • AjaxMinCommandPrompt.bat
    • AjaxMinCommandPromptVars.bat
 
<programfiles>\Microsoft\Microsoft Ajax Minifier\net20
    • AjaxMin.dll
    • AjaxMinifier.exe
 
<programfiles>\Microsoft\Microsoft Ajax Minifier\net35
    • AjaxMin.dll
    • AjaxMinTask.dll
 
<programfiles>\MSBuild\Microsoft\MicrosoftAjax
    • AjaxMin.dll
    • AjaxMinTask.dll
    • AjaxMin.tasks
    • AjaxMin.targets
    • AjaxMinTask.targets
 
<programfiles>\MSBuild\Microsoft\MicrosoftAjax\net35
    • AjaxMin.dll
    • AjaxMinTask.dll
    • AjaxMin.tasks
    • AjaxMin.targets
    • AjaxMinTask.targets
 

 

Old documentation can be found on the ASP.NET site: http://www.asp.net/ajaxlibrary/AjaxMinDocumentation.ashx

Last edited Feb 25, 2014 at 5:58 PM by ronlo, version 38

Comments

Ylazy Mar 12 at 1:36 AM 
DON'T COPY-PASTE ABOVE EXAMPLES or it WILL NOT RUN.
Type it yourseft to use MINUS instead DASH

l0basetom May 18, 2015 at 7:50 PM 
I noticed that Microsoft Ajax Minifier v4.47 generates slight smaller files than v5.14. After comparing two minified files closely, I noticed that they started to diverge here...

v4.47: `fade:function(n){var i=t,f;i!==u&&n===1||i!==0&&n===-1?(f=r,u-i<r&&n===1?f=u-i:t<r&&n===-1&&(f=i) ...`

v5.14: `fade:function(e){var b=a;if(b!==c&&e===1||b!==0&&e===-1){var f=d;if(c-b<d&&e===1)f=c-b;else if(a<d&&e===-1) ...`

What are the reasons why this change was made in the later version? I'm wondering if the decision to preserve the if/else pattern is more performant than using the ||/?: pattern.

ronlo Dec 16, 2013 at 4:59 PM 
The reason you don't see -hc in the documentation is that it is no longer supported. What it used to do it combine multiple duplicate constant literals into a single variable and replace the constants with the variable. Although it made the minified sources smaller, it had two serious drawbacks:
1. it made the resulting JavaScript run slower, and
2. if you were a good site administrator and turned GZIP on for your static files, the resulting compressed file was larger that if you didn't use the option!
Either thing is bad in its own right, but combined was unacceptable -- so the switch is now ignored. I'll add a section on switches that are no longer supported.

ronlo Jul 3, 2012 at 12:34 AM 
@Aukl - the NuGet package is for adding a reference to the DLL into your Visual Studio project. It doesn't install the command-line version of the tool. (Sorry; I had posted a really long reply about the Visual Studio library manager before I realized you were trying to run the EXE.) To get the EXE you will need to download and install the MSI.

AukI Feb 18, 2012 at 8:19 AM 
How to use it in the Nuget Console ? I tried this from scott hanselman's blog but it doesn't work either.
Any suggestions?

Console Output:


PM> set PATH=%~dp0;"C:\Program Files\Microsoft\Microsoft Ajax Minifier\"
C:\Program Files\Microsoft\Microsoft Ajax Minifier\
PM> ajaxmin -clobber Styles/main.css Styles/default.css Styles/colorbox.css Styles/nivo.css Styles/liteaccordion.css -o css\esquire.v1.min.css
The term 'ajaxmin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:8
+ ajaxmin <<<< -clobber Styles/main.css Styles/default.css Styles/colorbox.css Styles/nivo.css Styles/liteacc
ordion.css -o css\esquire.v1.min.css
+ CategoryInfo : ObjectNotFound: (ajaxmin:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

esben2000 Aug 1, 2011 at 9:15 AM 
Hi Ronlo. Thank you for this very nice tool. Is there somewhere I can find some documentation for all the settings?

ronlo Jun 10, 2011 at 4:19 PM 
Most of the stuff out there on the web that you find that mention options like "-h" and "-hc" were written based on the original version of the code first released to the web. There have been many updates since then, and one of the things that have happened is that the options and switches have been totally revamped. For instance, instead of single-letter switches, more verbose switches have been added -- run AjaxMin with the -? option to get the complete list. The -H option is now obsolete; by default AjaxMin will minify with the same local-renaming features, so the vast majority of developers will only need to do something like "ajaxmin.exe inputfile1 inputfile2 inputfileN -o outputfile" to get great minified JavaScript and CSS.

zeschnoz Jun 9, 2011 at 12:04 AM 
Hello, any update on the documentation? One thing that I see everywhere is the -hc command line option, however that's not listed under /? of the tool. It does produce smaller code, but what considerations should be made? I hope the documentation can clear this up.