Skip Navigation Links

Online JavaScript Minifier - using the Microsoft Ajax Minifier

This is a JavaScript minifier that use the brilliant Microsoft Ajax Minifier. The MS Ajax minifier can do simple minifying (with no renaming) or it can do the great job of also obfuscating (hypercrunching) the content. The settings is populated with the default settings. You can read more on Scott Gu's blog.


Input (text or file) Output

This is text from the help file of the Microsoft Ajax Minifier

  • CollapseToLiteral: convert “new Object()” to “{}” and “new Array()” to “[].” And of course, “new Array(1,2,3,4,5)” becomes “[1,2,3,4,5]” and “new Array(“foo”)” becomes “[“foo”]”. However, “new Array(5)” does not get crunched, because that makes an array with five initial slots – it’s not the same as [5].
  • CombineDuplicateLiterals: combine duplicate literals into local variables. So the code:
    function foo(a)
        a.b = 12345;
        a.c = 12345;
        a.d = 12345;
        a.e = 12345;

    gets changed to:

    function foo(a)
        var b=12345;

    The savings are much more dramatic with large, frequently-used strings. Works with numbers, strings, nulls, and this-pointers. The this-pointers only get crunched within the current scope, since child functions might have a different meaning for the pointer. It will also only pull out reused variables within function scopes – it won’t create a global variable with the constant, as that may interfere with other global variables. For the maximum crunching, wrap all your code within a namespace function scope.

  • EvalTreatment: Normally an eval statement can contain anything, including references to local variables and functions. If it is expected to do so, when the tool encounters an eval statement, that scope and all parent scopes cannot take advantage of local variable and function renaming because things could break when the eval is evaluated and the references are looked up. To reduce the amount of resulting minification but make sure that all possible references in evaluated code will hold true, use the MakeAllSafe value. However, sometimes the developer knows that he’s not referencing local variables in his eval (like when only evaluating JSON objects), and this switch can be set to Ignore to make sure you get the maximum reduction in resulting code size. Or alternatively, if the developer knows the code being evaluated will only access local variables and functions in the current scope and nowhere else, the MakeImmediateSafe value can be specified and all parent scopes will still rename their locals. Very dangerous setting; should only be used when you are certain of all possible behavior of evaluated code.
  • IndentSize: for the multi-line output feature, how many spaces to use when indenting a block (see OutputMode).
  • LocalRenaming: renaming of locals. There are a couple settings: KeepAll is the default and doesn’t rename variables or functions at all. CrunchAll renames everything it can. In between there is KeepLocalizationVars, which renames everything it can except for variables starting with L_. Those are left as-is so localization efforts can continue on the crunched code.
  • MacSafariQuirks: There was one quirk that Safari on the Mac (not the PC) needed that we were crunching out: throw statements always seem to require a terminating semicolon. Another Safari-specific quirk is that an if-statement only contains a function declaration, Safari will throw a syntax error if the declaration isn’t surrounded with curly-braces. Basically, if you want your code to always work in Safari, set this to true. If you don’t care about Safari, it might save a few bytes.
  • OutputMode: SingleLine crunches everything to a single line. MultipleLines breaks the crunched code into multiple lines for easier reading (won’t drive you insane trying to debug a single line). The only difference between the two outputs is whitespace. (see also: IndentSize).
  • RemoveUnneededCode: Should be set to true for maximum crunching. Removes unreferenced local functions (not global functions, though), unreferenced function parameters, quotes around object literal field names that won’t be confused with reserved words, and it does some interesting things with switch statements. For instance, if the default case is empty (just a break), it removes it altogether. If there is no default case, it also removes other empty case statements. It also removes break statements after return statements (unreachable code).
  • StripDebugStatements: removes “debugger” statements, any calls into certain namespaces like $Debug, Debug, Web.Debug or Msn.Debug. also strips calls to the WAssert function.