Microsoft Ajax Minifier
Ajax Minifier is a tool created by MSN team Ron Logon. The Microsoft Ajax Minifier enables you to improve the performance of your web applications by reducing the size of your Cascading Style Sheet and JavaScript files. The Ajax Minifier performs the following processing to reduce the size of the file.
- Delete comment
- Delete unnecessary spaces
- Delete unnecessary semicolons
- Delete unreferenced functions
- Delete unnecessary parentheses
- Shorten local variable and function name
- Adjust string quotation and double quotation
- Combining adjacent variable declarations
- Delete code not executed
- etc.
In Ajax Minifier, there was a dll version that can be used by calling an API from a program, and a msi installer version including an exe file that can be used alone.
The dll version can be acquired as AjaxMin by nuget even now (January 2019).
The msi installer version including the exe file was published as an AjaxMin project in CodePlex. But CodePlex ended in 2017.
CodePlex was Microsoft's free, open source project hosting site, which ran from 2006 through 2017.
Now We can only download the data as an archive.
It is inconvenient that you can not get an installer etc, so leave various information here as a record, and make it possible to download the final version.
We will make it available for download from this site, but all of the module’s rights are found in original creator Ron Logon.
Below this section, in order to retain various information as a record that can be referred to, post the information at that time as it is.
The project itself is stopped at the end in January 2015. Therefore, we can not report bugs, feedback, etc. at present. Please keep the contents to the reference level.
Project Description
The Microsoft Ajax Minifier enables you to improve the performance of your web applications by reducing the size of your Cascading Style Sheet and JavaScript files.
Minify both JS and CSS files, and now optionally produce Source Maps for JavaScript files.
Use the -analyze option on the command-line to provide lint-style syntax checking and variable analysis of your code.
Use the -pretty option on the command-line to output in a nice, easy-to-read multi-line format (good for un-minifying minified code).
JavaScript and CSS files minified with Ajax Minifier should work as-is; you shouldn’t have to do anything special in your code to get good results. If your file doesn’t work after minification, first check to see if your JavaScript code contains eval statements that might require you to use a different –evals switch. If your file still doesn’t work, please file a report on the “Issue” page so I can get Ajax Minifier fixed.
If you have any new feature requests, please feel free to bring them up on the “Issues” page. We cannot guarantee feature requests will make it into the code.
Offical NuGet Package
There is an official NuGet package for the DLL version of Microsoft Ajax Minifier, if you prefer to manage your C# projects in that manner:
http://nuget.org/packages/AjaxMin
AjaxMin was created by Ron Logan.
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Version History
2015-01-28 Microsoft Ajax Minifier 5.14
- Issue #21611 – add
"noswap"
option to CSS -colors switch so that names don’t get swapped with shorter hex values, or hex with shorter name values. make the default -colors switch value be HEX, not STRICT. - Fix for issue #21680 – regular expression literal parsing error
2014-12-16 Microsoft Ajax Minifier 5.13
- fix issue #21609 – escaped closing bracket inside regular expression literal set not being escaped.
- fix issue #21549 – comma-separated lists in progid values must have trailing whitespace.
- fix issue #21162 – bad OP= optimization.
- Add XDomainRequest and DocumentTouch as known globals.
- Add debug timing for CSS (though not as detailed as JS debug timing).
- Perf: add a string builder pool so we aren’t creating/destroying string builders all the time.
2014-11-19 Microsoft Ajax Minifier 5.12
- Fix for issue #21164 – variable renaming issue when -evals:immediate switch is used.
- Fix for issue #21292 – null-reference exception when using the scriptsharp source map generator.
- Fix for issue #21494 – sourceMappingUrl comment not added when using the Minifier object.
- remove empty CSS rules or @media directives when their blocks are empty.
- add some more known global names
- minor performance improvements.
2014-07-01 Microsoft Ajax Minifier 5.11
- Fix for issue #21057 – don’t strip spaces before CSS !important token.
- Fix for issue #20912 – support for CSS :any and :matches pseudoclasses.
2014-05-27 Microsoft Ajax Minifier 5.10
- Fix for Issue #20875 – echo switch doesn’t work for CSS
- CSS should honor the SASS source-file comments
- JS should allow multi-line comment directives
2014-04-26 Microsoft AjaxMinifier 5.9
Just a couple minor features I needed for work:
- new -amd switch that automatically adds
"define"
and"require"
to the known globals list, and removes duplicate named modules{{define("modulename",...)}}
from the combined source file. - stand-alone tokens or tokens that are the only contents of a string literal will be examined, and if they start with CurrentCulture, the dotted path will be resolved against the thread’s CultureInfo.CurrentCulture object and replace the token.
For example:
{{ var monthNames = %CurrentCulture.DateTimeFormat.MonthNames%; var percent = "%CurrentCulture.NumberFormat.PercentSymbol%"; }}
: will result in:
{{ var monthNames=["January","February",...],percent="%" }}
: and the actual values will vary by the thread’s current culture. If the culture isn’t getting set elsewhere, you can set the thread’s current culture with the -culture:LL-CC switch. This switch, however, will set the thread’s current culture and not reset it back to what it was, so beware of any unintended side-effects.
2014-02-28 Microsoft Ajax Minifier 5.8
- Issue #20705 – add support for SharePoint Theming comments in CSS.
- Issue #20719 – manifest processing was ignoring
<resource>
elements. - Issue #20739 – in an expression-level call to JSParser.Parse, do not convert commas to semicolons because they aren’t statements, but actual subexpressions.
2014-01-11 Microsoft Ajax Minifier 5.7
- Add support for “typed array” constructors.
- Fix for issue #20611 – Chrome implemented a proposed errata for Media Queries that requires whitespace before the “and” conjunction. Make sure the CSS minifier doesn’t strip it out.
2013-12-18 Microsoft Ajax Minifier 5.6
- Fix for bug 20541 – in CSS strings, and ASCII-9 is not a
"\t"
, ASCII-10 is not"\n"
, ASCII-13 is not"\r"
, and ASCII-12 is not"\f"
. - Fix bug 20517 – in CSS, invalid color hash values were parsed incorrectly and caused a slew of other irrelevant errors. Just log the invalid hash color and continue on.
- Make the
<input>
and<output>
elements in manifest files accept the legacy"enc"
attribute name in addition to the newer"encoding"
attribute. Changed the online documentation to reflect the new name. - throw invalid-switch errors when switches incompatible with
-pretty
are used together. (NOTE: the -pretty switch is a special switch that does not change the input other than to add whitespace to make it more readable, so any switches that cause the input to be modified cannot be used with it. Please use the -line switch to make modified code output on multiple lines.) - added the ability to use -pretty with JSON input, so you can use it to make JSON output returned from services a little easier to debug.
2013-12-09 Microsoft Ajax Minifier 5.5
- Fix bug #20499, where the Append method was marked as internal. Also, the Manifest build task was always showing all errors and warnings; changed it to respect any -warn:N arguments in the manifest settings to be able to crank down the severity threshold.
2013-12-03 Microsoft Ajax Minifier 5.4
- Fix potential infinite loop problem introduced in 5.3. Add option to pretty-print JSON data.
2013-11-16 Microsoft Ajax Minifier 5.3
- Switch back to new SourceMap v3 syntax of
//#
for the comment, not//@
- more pre-defined globals
- fix issue #20273
- fix issue #20298
- fix issue #20417
- fix issue #20420
2013-09-30 Microsoft Ajax Minifier 5.2
Mostly internal code tweaks.
- added -nosize switch to turn off the size- and gzip-calculations done after minification.
- removed the comments in the build targets script for the old AjaxMin build task (discussion #458831).
- Fixed an issue with extended Unicode characters encoded inside a string literal with adjacent
\uHHHH\uHHHH
sequences. - Fixed an IndexOutOfRange exception when encountering a CSS identifier that’s a single underscore character (_).
In previous builds, the net35 and net20 folders created by the MSI were just copying the .NET 4.0 DLLs due to a build script copy/paste error. That should be resolved; apologies to anyone encountering issues with using AjaxMin with older .NET frameworks.
REMINDER: the 5.x release includes breaking changes from 4.x. See Migrating from v4 to v5 for more information.
2013-09-16 Microsoft Ajax Minifier 5.1
- Reverted all the DLLs’ “Platform Target” project settings to “Any CPU.” The problem with putting them to “x86” is that a host application built to “Any CPU” or “x64” fails to load the DLL. So the EXEs will remain “x86”; only the DLLs are reverted to “Any CPU”. This should fix Issue #20199.
REMINDER: the 5.x release includes breaking changes from 4.x. See Migrating from v4 to v5 for more information.
2013-09-16 Microsoft Ajax Minifier 5.0
! New major version release with breaking changes!
If you are using AjaxMin on the command-line, or via the library’s Microsoft.Ajax.Utilities.Minifier object’s MinifyJavaScript or MinifyStyleSheet methods, or via the provided build tasks, no breaking changes should be present.
If you are creating and using JSParser objects directly, creating and using classes derived from IVisitor, and/or defining your own custom AST node classes, you will need to perform some migration work. See Migrating from v4 to v5 for more information.
!! Support for some EcmaScript 6 syntax.
Please see EcmaScript 6 Supported Syntax for more information.
!! Bug Fixes:
- fix for Issue #20189 – build task doesn’t build when source and destination are the same file.
2013-07-12 Microsoft Ajax Minifier 4.96
- Fix for issue #19957: EXE should output the name of the file(s) being minified.
- Discussion #449181: throw a Sev-2 warning when trailing commas are detected on an Array literal. Perfectly legal to do so, but the behavior ends up working differently on different browsers, so throw a cross-browser warning.
- Add a few more known global names for improved ES6 compatibility
- update Nuget package to version 2.5 and automatically add the AjaxMin.targets to your project when you update the package. This target will automatically build any files in your project with the extension .AjaxMin using the AjaxMinManifestTask.
- get rid of multiple code paths and the maintenance nightmare of maintaining them separately for normal, echo, and preprocess-only. The preprocess-only path wasn’t even parsing the input files.
- if the length property is being applied to a string literal which has a known length, replace the property access with the actual length.
- remove most custom exceptions, and remove the serialization code from the remaining one. Needed for WebGrease and its partially-trusted callers scenarios.
2013-06-25 Microsoft Ajax Minifier 4.95
- update parser to allow for CSS3 calc( function to nest.
- add recognition of -pponly (Preprocess-Only) switch in AjaxMinManifestTask build task.
- Fix crashing bug in EXE when processing a manifest file using the -xml switch and an error message needs to be displayed (like a missing input file).
- Create separate Clean and Bundle build tasks for working with manifest files (AjaxMinManifestCleanTask and AjaxMinBundleTask). Removed the IsCleanOperation from AjaxMinManifestTask — use AjaxMinManifestCleanTask instead. Updated the provided .targets file as such.
- Add ability for CSS parser to recognize CSS-style multi-line #SOURCE comments, since single-line comments aren’t actually valid CSS syntax. Needed because the new bundling task needs to output valid CSS, since the results are exposed and not immediately consumed by the tool.
2013-06-17 Microsoft Ajax Minifier 4.94
- add dstLine and dstCol attributes to the
-Analyze
output in XML mode. - un-combine leftover comma-separates expression statements after optimizations are complete so downstream tools don’t stack-overflow on really deep comma trees.
- add support for using a single source map generator instance with multiple runs of MinifyJavaScript, assuming that the results are concatenated to the same output file.
2013-06-03 Microsoft Ajax Minifier 4.93
- Added
-esc[:BOOL]
switch (CodeSettings.AlwaysEscapeNonAscii property) to always force non-ASCII character (ch > 0x7f) to be escaped as the JavaScript\uXXXX
sequence. This switch should be used if creating a Symbol Map and outputting the result to the a text encoding other than UTF-8 or UTF-16 (ASCII, for instance). - Fixed a bug where a complex comma operation is the operand of a return statement, and it was looking at the wrong variable for possible optimization of += to just +.
2013-05-28 Microsoft Ajax Minifier 4.92
- Fixed issues around certain numeric literals that have member-operators applied to them.
- InputFolder was being ignored by ManifestTask, leading to incorrect “missing input file” errors.
2013-05-07 Microsoft Ajax Minifier 4.91
- Add optional
"origin"
property to manifest<input>
elements. Settingorigin="external"
on an input file makes the build process ignore all warnings for the given file. - Add the .NET 3.5 DLLs (AjaxMin.dll and AjaxMinTask.dll) to the NuGet package tools\net35 folder.
- Add a “clean” step for the AjaxMinManifestTask so that output files specified in the manifest can be deleted in the build’s clean process.
2013-04-26 Microsoft Ajax Minifier 4.90
- Fix for Issue #19632 – when generating source maps, need to wrap the //@ sourceMappingURL=url comment inside a multiline comment to keep IE from thinking it’s a conditional-compilation comment and throwing an error.
- Fix for Issue #19639 – when using the -minify:no switch, don’t optimize out empty blocks, and especially not empty else-clauses. The switch means don’t modify the DOM, so DOM modifications should not be performed.
2013-04-23 Microsoft Ajax Minifier 4.89
- Fix for second follow-up issue discovered in Issue #19459. Inner scopes known at compile time that reference a field in an outer scope that isn’t known need to add that field to the avoid-names list before renaming their local variables, because we can’t rename that outer variable (because it’s in an unknown scope), and we don’t want to accidentally reuse the name. Only an issue when the -evals:safeall switch is used, especially when minifying already-minified files.
2013-04-19 Microsoft Ajax Minifier 4.88
- Fix for issue #19459 for the BUILD TASKS. When concatenating source files, append blank lines and semicolons as appropriate to make sure files are terminated properly.
2013-04-12 Microsoft Ajax Minifier 4.87
- Fix for issue #19459 – need to insert semicolons between concatenated files if they don’t already end with a semicolon.
Potential Breaking Change
To concatenate partial script files without getting semicolons added between them, add a single-line comment at the end of your partial script files, ending with a semicolon: //; The code is simply doing a text-comparison for the trailing semicolon (ignoring terminating whitespace), so this will be enough to signal AjaxMin to not add the semicolon and break the assembled partial code files. - Fix for issue #19559 – don’t replace single-reference object literal variable declarations when the reference is within an iteration statement.
- Somehow the “unreferenced variable” warnings were previously accidentally disabled and I didn’t notice; reinstating those warnings.
2013-03-29 Microsoft Ajax Minifier 4.86
- Fix file concatenation issues
2013-03-21 Microsoft Ajax Minifier 4.85
JavaScript:
- Don’t lose important comments at the end of block or functions (issue #19416).
- fix bad optimization of Array shift calls that are the only reference to a variable initialized with an array literal (issue #19440).
- created separate EmptyStatement node instead of using an empty block.
- ignore important comments that would otherwise interfere with the normal parsing of the source code.
CSS:
- don’t strip off units for zero-value Angles, Times, Frequencies, or Resolutions.
2013-02-11 Microsoft Ajax Minifier 4.84
- Fixed a bug whereby passing a null or empty string to the CssParser. Parse(string) method would throw an exception. The command-line or task paths for executing the code were not affected by the bug.
2013-02-06 Microsoft Ajax Minifier 4.83
- Fixed issue #19309 – regexp literals with the “g” global flag cannot be treated as constants as they contain state that is used in subsequent exec() calls. Don’t move them from a variable to an in-place literal.
- Fixed issue #19296 – ///#DEBUG blocks were getting removed unless the DEBUG preprocessor define existed, and totally ignored the StripDebugStatements CodeSettings flag. Legacy builds switched off that property, so people broke when upgrading. Changed the logic to leave those comments in if either the DEBUG preprocessor define exists OR the StripDebugStatements flag is false. Default is still to remove.
- Fixed issue where throw statements could possibly line-break between the throw keyword and its operand (not allowed in JS syntax) when the -line:N switch is used to break lines after they have crossed the N-character threshold.
- comments containing
"@preserve"
or"@license"
should be treated as important comments and not removed. This is an alternative way to create important comments, {“beyond the current /*! … */ and //! … formats”}.
2013-02-05 Microsoft Ajax Minifier 4.82
Fixing a bug around invalid JS (for the current ES5 specs): function declarations at other than source-element scopes. Technically it’s invalid to put a function declaration within, say, an if-block; but browsers allow it — unfortunately they treat them differently since it’s not a spec’d scenario. Some declare the name immediately as if it were at the source element level; some don’t declare the name until the declaration is “executed.” The difference could lead to hard-to-debug cross-browser issues.
AjaxMin was updated a while back to support the upcoming ES6 spec, which calls for block-level scoping of lexical elements, including function declarations. So it will be perfectly valid to declare a function within an if-statement — but the declaration will only be scoped to that block and not visible outside it. The end result is that if someone writes some JavaScript to the current browsers thinking their function declaration will be scoped to the variable scope, AjaxMin will break that code upon minification by renaming it to something that doesn’t collide within the lexical scope — but might collide in the variable scope, clobbering values.
Updated AjaxMin such that it maintains a linkage to the variable scope so the lexical function declaration won’t collide with another variable-scope field during renaming. Also added a low-sev warning about the situation, since most people aren’t coding ES6 yet anyway. Will have to revisit later; maybe add a JS version switch for ES5 vs ES6.
2013-01-21 Microsoft Ajax Minifier 4.81
- Fixed issue where the AjaxMin build task was ignoring any
-enc
switches applied to the task and only outputting as UTF-8 with no BOM.
2013-01-15 Microsoft Ajax Minifier 4.80
- Fix for issue #19190 in the AjaxManifestTask build task: the manifest file itself should be treated as an input file and modification to it should cause output to be regenerated during build.
2013-01-14 Microsoft Ajax Minifier 4.79
- NEW SETUP PROJECT.
- If for some reason the MSI doesn’t work for you, please let me know immediately. I had to create a new WiX setup project as part of the VS2012 migration. It should work just fine, but I get nervous any time I touch the MSI itself.
- Fix for Issue #19055 – Manifest XML file didn’t accept .RESX resources, just .RESOURCES.
- Fix for issue 19087 – used to throw an error if it encountered a CSS3 @charset rule anywhere other than the exact first character in the file. Now it’s a little more forgiving if the first few characters are BOM characters. Also, it will now continue to process the input properly, and throw a lesser-severity error that is more descriptive of what is actually going on (@charset not at start of file).
- Fix a crashing issue when the input JS ended in an empty and unterminated string delimiter.
- Fixed the context of the returned overall parsed script block; the end point was incorrect (didn’t include the proper line/column numbers).
- Various ongoing code-analysis maintenance fixes (too much complexity in many methods).
- moved the source project to Visual Studio 2012; had to migrate the setup project to WiX, since the old VS Setup projects are no longer supported in VS2012.
2012-12-07 Microsoft Ajax Minifier 4.78
- Fix for issue #18924 – using -pretty option left in ///#DEBUG blocks.
- Fix for issue #18980 – bad += optimization caused bug in resulting code. Optimization has been removed pending further review.
One Reply to “Microsoft Ajax Minifier”