Ajax Minifier will minify either JavaScript or CSS stylesheets. There are common switches for both, switches just for JavaScript, and switches for CSS stylesheets.

 

Overall Syntax:

ajaxminifier[.exe] [([-JS[:JSTYP]] [JSOPTS])|([-CSS[:CSSTYP]] [CSSOPTS])] OPTS* ((IFILE* [-out OFILE] [-map MFILE])|
(-xml XFILE [-out ODIR]))

 

Usage Syntax:

  • Text to be entered as-is will be lower-case. Patterns and other objects will be specified in UPPER-CASE.
  • Grouped items will be specified between ( and ) characters.
  • Optional text will be specified between [ and ] characters.
  • A choices between text options is represented as a group of options separated by a | character.
  • If something is to be repeated zero or more times, it will be followed by an asterisk (*)
  • If something is to be repeated one or more times, it will be followed by a plus-sign (+)

 

  • BOOL can be (true | false | t | f | yes | no | y | n | 1 | 0 | none); case-insensitive.
  • N is a valid non-negative integer: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9)+.
  • DEC is a valid decimal integer: [+ | -]DEC.
  • HEX is a valid case-insensitive hexadecimal integer: (DEC | a | b | c | d | e | f)+.
  • ERRCODE is a case-insensitive error code (e.g.: JS1028 or CSS1059) or the word “ALL”.
  • IDENT is a valid case-sensitive JavaScript identifier.
  • NAME is a valid case-insensitive JavaScript identifier.
  • NS is a valid case-sensitive JavaScript namespace: IDENT[.IDENT]*
  • ENC is a valid .NET text encoding scheme. Valid values can be found on this page; use the “Name” column in the big table down the page.
  • IFILE is a valid path to an existing input file.
  • OFILE is a valid path to the output file. If the file exists, the program will not overwrite by default. See the –clobber option.
  • XFILE is a valid path to an existing XML input file.
  • RFILE is a valid path to an existing .RESX or .RESOURCES file.
  • NFILE is a valid path to an existing XML identifier-renaming file.
  • MFILE is a valid path to a writable output source map file.
  • MTYPE is a supported source map implementation name. Either XML or V3 (case-insensitive).
  • ODIR is a valid path to an output folder. The folder will be created if it doesn’t exist.
  • CSSTYP can be full (default; expects full stylesheet), or decls (only list of declarations, as in the style attribute of an HTML element).
  • AOPTS is a comma-separated list of tokens specifying –analyze options. Currently only two tokens are allowed: xml and/or out. The former causes the analyze scope report to be in XML format, rather than the default text format; the latter causes the scope report to be written to the path specified in the next command-line argument (APATH).
  • APATH is a valid path to a scope-report output file. The file will be overwritten if it exists.

Universal Options (OPTS):

  • -out OFILE is used to specify the name of the output file to create, if zero or more input source files are specified. The switch can be shortened to –o.
  • -aspnet[:BOOL] turns on or off support for inline ASP.NET <% … %> substitutions. Default value is False.
  • -braces:(new|same|source)  when output is set to multiple lines, determines whether opening braces are written on their own new line, at the end of the previous line, or reflecting what is in the source code. Default is new.
  • -noclobber[:BOOL] when the Boolean flag is true (or not supplied), will never overwrite an existing file. When false, the default behavior is applied: will overwrite an existing file only if its read-only flag is not set.
  • -clobber[:BOOL] when the Boolean flag is true (or not supplied), will always overwrite an existing file, even if the read-only flag is set. When false, the default behavior is applied: will overwrite an existing file only if its read-only flag is not set. Not supported in the MSBuild task.
  • -config:NAME use this switch when using manifest files as the input, to specify a configuration name, such as “Debug” or “Release,” referenced by the config attribute of an <arguments> element. Has no effect when using JavaScript or CSS files as inputs.
  • -define:NAME(,NAME)* specifies one or more C-preprocessor-style names that can be used to conditionally output code based on build settings and configurations. No names are defined by default.
  • -echo tells Ajax Minifier to simply echo the input to the output. Can be useful in debug builds where you want all the error checking Ajax Minifier does, but you don’t want to alter the source files. Not supported in the MSBuild task.
  • -enc:(in|out) ENC  specifies the input or output text encodings to use to read or write files. By default, Ajax Minifier will try to automatically determine the text encoding of input files; for instance, if the UNICODE byte markers are at the front of the file. If Ajax Minifier cannot automatically select the proper text encoding for your source files, use the –enc:in switch to specify the input encoding to use. By default, Ajax Minifier will output using the UTF-8 encoding. To use a different output encoding, use the –enc:out switch.
  • -help or –? will display the usage text, an abbreviated version of this page.
  • -ignore:ERRCODE(,ERRCODE)* ignore one or more possible errors. Specifying “ALL” will turn off all error or message reporting.
  • -line[:[N][,[multiple|single][,[N]]]] breaks output lines after they reach N characters long. Not specifying a character count sets the default value of int.MaxValue-1000. Lines usually won’t break exactly at N characters; they will break sometime after that position, so if you have an absolute maximum, set the value N at some point before that to allow for the overflow. Escaped characters will also add line length, so if your code uses a lot of \uXXXX escapes, be sure to allow for enough buffer space. The second option is whether to break statements along multiple indented lines (multiple) or to put them all on the same line (single), according to the previous threshold value; default is single. The last option is how many spaces to use for each indent level if multi-line output is used; default is 4. Any or all of the three value may be omitted to indicate the default value. “M” can be used as shorthand for “multiple,” and “S” for “single”; eg: –line:M will cause the output to be in multi-line format.
  • -out OFILE output file to create from concatenating all input files.
  • -pretty[:N] turns off minification and causes the output of Ajax Minifier to be in multi-line format, with proper tabbing added, assuming N space characters per indention level. The default output of Ajax Minifier is single-line, and the default indention level when the –pretty switch is used is 4 space characters. This switch can be used to help make already-minified code easier to read (although it won’t help with variable renaming or any other minification changes). The difference between the input and output files will only be whitespace. This switch is not compatible with any other switch that would cause the sources to be changed other than the addition or removal of whitespace, including the preprocessing and removal of debug statements (see –debug switch for JavaScript).  This switch can be shortened to –p[:N].
  • -res[:IDENT] RFILE uses a resource file (either a .RESX or .RESOURCES file) to be used to specify localized strings via an object named IDENT. If no identifier is specified on the switch, the name “Strings” is assumed. For example, if the switch –res:Strings bar.resx is specified, all instance of Strings.IDENT will be replaced with a string literal created from the item named IDENT within the resource file. If no resource of that name is found, it will be replaced with an empty string literal. No resource files are specified by default. This switch can be shortened to –r[:IDENT].
  • -silent tells Ajax Minifier not to output any error, warning, or informational text. This switch can be shortened to –s.
  • -term ensures the generated output ends with a semicolon or other valid terminator. This is useful if Ajax Minifier is used to generate a series of code snippets that will be concatenated together at a later time.
  • -version will output only the version number of the binary. This can be used in build scripting, if the version needs to be checked.
  • -warn[:N] specifies the warning level for error and warning messages. By default, only the top-level errors are reported (level 0). To increase the number of errors or warnings Ajax Minifier generates from your code, increase the integer value via this switch. The switch can be shortened to –w[:N].
  • -xml XFILE is used to specify an XML input file that in turn specified which source file(s) to minify into which output file(s). This switch can be shortened to –x XFILE.
  • -out ODIR can be used in conjunction with the –xml switch to specify the output directory for all output files specified in the input XML file.

 

JavaScript-Specific Options (JSOPTS):

  • -analyze[:AOPTS [APATH]] provides extra analysis for your code. It bumps the warning level up to its highest setting (which can be overridden with the –warn switch), and will provide a scope report detailing all the fields in all the lexical scopes of your program. The default format of the report is text, but you can specify xml as one of the comma-separated AOPTS tokens to change the format to XML for easier programmatic processing of the data. You can also have the report written to a separate file with the out token of AOPTS; when that token is specified, the next command-line argument is the path (APATH) to the output file to be written. Only specify the APATH option if out is one of the AOPTS tokens, or else it will be mistaken for an input file path. The switch can be shortened to –a.
  • -cc[:BOOL] turns on or off support for Internet Explorer conditional-compilation comments. Ajax Minifier will try to preserve conditional comments by default, with some limitations. To completely ignore and strip any and all conditional-compilation comments, specify this switch with the False value. The default value is True.
  • -comments:(important|none) specified whether or not important comments will be retained in the output. Important comments are frequently used by developers to specify copyright or licensing information that needs to be retained in distributed scripts. Important comments are regular comment syntax but with an exclamation mark for the third character. For example: /*! important comment */. The default value is important.
  • -debug[:BOOL(,NS)*] specifies whether to keep “debug” statements in the out, and optionally to specify those debug namespaces. To specify a different set of debug namespaces, follow the Boolean flag with a comma-separated list of your own namespaces. When specifying namespaces in this manner, the default set is deleted, so be sure to include all debug namespaces you wish to use, even if they are in the default set. The default setting is False,Debug,$Debug,WAssert,Msn.Debug,Web.Debug. (Note that the stripping of debug statements is not compatible with the –pretty switch, which only modifies the whitespace of the input file. Use the –line switch to generate multi-line output when modifying the input code.)
  • -esc[:BOOL] whether to always escape non-ASCII characters in the output as \uXXXX sequences (true), or the leave the escaping entirely up to the output encoding and what characters it supports (false). Default value is false.
  • -evals:(ignore|immediate|safeall) specifies how eval statements are to be treated. This is an important switch to be aware of. By default Ajax Minifier will ignore any eval statements, which can break your minified code if it contains eval statements that reference named local variables or functions. This is because by default Ajax Minifier will also rename local variables and function, but it doesn’t modify the text passed to the eval function, so those references may break. If you minify code and it stops working properly, check the code for eval statements. If there are any, try specifying one of the other two –evals switch options. The “immediate” options will not rename any variables or functions within the same scope as any eval call; the “safeall” option will not rename any variables or functions not only in the same scope as any eval call, but also in any parent scopes. This will seriously impair the minification of your code, but should ensure that any calls to the eval function will work as expected. The default setting is ignoreall.
  • -fnames:(onlyref|lock|keep) specifies how Ajax Minifier treats named function expressions. By default, Ajax Minifier will remove the names on all named function expressions when the name is never referenced. The “lock” option will not only keep all function expression names, but will also lock those names so they cannot be renamed. The “keep” option will keep the names, but will allow them to participate in the renaming process. The default setting is onlyref.
  • -global:IDENT(,IDENT)* specified one or more known global identifiers. When Ajax Minifier comes across a variable or function reference that it cannot resolve, it will treat the reference as if it points to a global object that is referenced somewhere else, and it will throw an error for an undefined global reference. If you know your code will reference global objects defined elsewhere, use this switch define those global objects so Ajax Minifier will not throw any errors when they are encounters. A common example for users of the jQuery library would be –global:jQuery,$. No global names are specified by default. This switch can be shortened to –g:IDENT(,IDENT)*.
  • -inline[:BOOL|force|noforce(,(BOOL|force|noforce))*] specifies whether or not to treat the code as if it will be inserted inline into an HTML page. Ajax Minifier will make sure that instances of </script> in string literals will be properly escaped. The default setting is True. The force option will force inline-safety on the source by throwing an error when potentially unsafe string literals are encountered; noforce does not (default is noforce).
  • -kill:DEC or –kill:0xHEX specifies one or more “kill switches.” This allows finer, more-granular control over which changes are made to the source file(s) to generate the minified code. This is an advanced option; see the Kill Switches page for more information. Default value is zero.
  • -literals:(eval|noeval) turns on or off the feature that evaluates literal expressions if the results are smaller than the original. For example, 5*24*60*60*1000 will be automatically changed to 432e6. The default value is eval.
  • -mac[:BOOL] specifies whether or not to add code to the output to ensure that bugs in current or previous versions of Safari will be safely addressed. For example, some versions of Safari will throw a script error if throw statements are not terminated with a semicolon. The default value is True.
  • -map:MTYPE MFILE is used to specify that a source map should be generated for the given output. The source map file will be created at the path MFILE, and the implementation to use is specified by the name MTYPE. There are two supported source map formats: XML (default) creates an XML format; V3 creates a JSON V3 format compatible with browsers such as Chrome.
  • -maproot PATH specified a value to use as the sourceRoot property in the V3 source map object.
  • -mapsafe[:BOOL] specifies whether to add characters to the V3 source map header to protect it against possible cross-site scripting attacks. If true, will add “)}]’” to the front of the file.
  • -minify[:BOOL] whether to run any minification optimizations beyond simple whitespace and comment removal on the parsed JavaScript code. By default the application will rename local variables and functions, reorder code, combine statements, etc. Use this switch to turn any code-modifications off.
  • -modern will set a couple kill switches: TreeModifications.CombineAdjacentExpressionStatements and TreeModifications.BooleanLiteralsToNotOperators. Modern app code written with JavaScript should not use those minification features, since the byte-code interpreters have a harder time with them.
  • -new:(collapse|keep) specifies whether or not to replace certain calls to certain constructors with smaller literal objects. For example, new Object() to {}, and new Array() to []. The default value is collapse.
  • -nosize will turn off the GZIP size-comparison messaging that is displayed in the output stream of the EXE tool.
  • -obj:(min|quote) whether to strip quotes from object literal property names that are valid identifiers (min), or to always quote them (quote). Default is to minify.
  • -pponly specifies that the input should be run through the preprocessor only, and not parsed into an AST tree and otherwise minified.
  • -rename:(all|localization|none) specifies whether or not to automatically rename local variables and functions. Global variables and functions are not automatically renamed, nor are property names. If “localization” is specified, only variables that do not start with “L_” will be renamed. The default value is all.
  • -rename:IDENT=IDENT(,IDENT=IDENT)* specifies variable, property, and function names to be manually renamed in the output. No renaming pairs are specified by default.
  • -norename:IDENT(,IDENT)* specifies certain identifiers to not participate in the automatic renaming feature. The identifier “$super” is reserved by default so the Prototype library will minify properly.
  • -rename NFILE specifies the path to an XML naming file to be opened and parsed, and renaming pairs specified in the XML will be used for renaming identifiers in the output. No XML file is used by default.
  • -rename:noprops is only applicable if –rename:IDENT=IDENT parameters are also used. By default, manual-renaming parameters will rename variable and functions as well as property names. This parameter causes property names to not be renamed when manual-renaming pairs are specified
  • -reorder[:BOOL] whether or not to reorder function and variable declarations, placing them at the top of their respective scopes. Default is true.
  • -strict[:BOOL] whether to force the input script into ECMA-5 strict-mode. Default is false.
  • -unused:(remove|keep) specifies whether unused code will be retained in the output. The default value is remove.
  • -js[:JSTYP] Normally the source type can be implied by the file extension “.JS”. If there are no extensions on the input files, if they are not the standard “.JS”, or if you are pulling the input from STDIN (no input files specified), use this switch to force the run to minify JavaScript sources. The type of input can be one of the following: JSON for JSON values; PROG or PROGRAM (default) for a JavaScript program source, as in code contained within and HTML <script> element; EXPR or EXPRESSION for a simple JavaScript expression; EVT or EVENT for an implicit event handler, as in code contained within an HTML onclick attribute; MOD or MODULE for an implicit ES6 JavaScript module, as in an external code file referenced from an import statement (implicit if the code contains one or more export statements); ES5 (default) for script assumed to be conforming to the EcmaScript 5 standard or ES6 for code conforming to the EcmaScript 6 standard (implicit if ES6-specific syntax encountered).

 

CSS-Specific Options (CSSOPTS):

  • -comments:(important|none|all|hacks) specifies how comments are treated in the output. If “important” is specified, only important comments are preserved. Important comments use an exclamation point as the third character, e.g.: /*! important comment */.  These can be used to specify copyright, license, or other information the developer intends to remain in the minified output. The “none” option allows no comments to go into the output. The “all” option allows all comments to be retained. The “hacks” option allows only a subset of comments matching some well-known and frequently-used CSS comment hacks to be preserved in the output. The default value is important.
  • -colors:(hex|strict|major|noswap) specifies how to treat colors in certain well-defined property values. If “hex” is specified, all colors are converted to hexadecimal values. If “strict” is specified, only color names that are recognized by all major browsers can be used (for example, “red” will be substituted for “#FF0000”). If “major” is specified, then color names recognized by most major browsers can be used. If "noswap" is specified, then names are not swapped with hex, nor hex swapped with names, regardless of which is shorter. The default value is hex.
  • -expr:(minify|raw) whether to leave CSS expressions as-is or to minify them as JavaScript expressions. Default is minify.
  • -css[:CSSTYP] Normally the source type can be implied by the file extension “.CSS”. If there are no extensions on the input files, if they are not the standard “.CSS”, or if you are pulling the input from STDIN (no input files specified), use this switch to force the run to minify CSS stylesheet sources.  The type of input expected is by default a fully-formed stylesheet. If you wish to minify the contents of an HTML style attribute, use the –css:decls switch to switch to declaration-list-only parsing.

 

Backwards-Compatibility and Unsupported Switches

Please don’t use the following switches. They are listed here for documentation purposes and may completely go away in a future release. Most turn on behavior that is now on by default; some were used for features that are no longer supported. For those that alter default behavior, please use the equivalent switches listed for each one. Most of these unsupported switches do not have options and only work one way (turn something on but not off, or off but not on); they do not support the [:BOOL] syntax.

  • -cl is completely ignored, and was previously used for a feature that is no longer supported.
  • -cs is completely ignored, and was previously used for a feature that is no longer supported.
  • -d is equivalent to –debug:false, which is now default behavior.
  • -e ENC or -eo ENC specifies the output encoding scheme. Please use –enc:out ENC.
  • -ei ENC specified the input encoding scheme. Please use –enc:in ENC.
  • -h turns on minification beyond simple whitespace- and comment-removal, which is now the default behavior. This flag is essentially ignored, but is the equivalent to –rename:all –unused:remove.
  • -hl turns on minification beyond simple whitespace- and comment-removal, but does not rename localization variables that begin with the prefix “L_”. This flag is equivalent to –rename:localization –unused:remove. Because –unused:remove is default behavior, please use –rename:localization instead.
  • -hc is equivalent to –h, which again is the default behavior and is now essentially ignored.
  • -hlc and –hcl are equivalent to –hl.
  • -i causes the input to be passed to the output without making any changes to it. Please use –echo.
  • -j is equivalent to –evals:ignore, which is now the default behavior.
  • -k is equivalent to –inline:true, which is now the default behavior.
  • -l turns off the replacement of the default replacement of new Object() with {} and new Array() with []. Please use –new:keep.
  • -m is equivalent to –mac:true, which is now the default behavior.
  • -v is completely ignored, and was previously used for a feature that is no longer supported.
  • -z adds a file-terminating semicolon. Please use –term:true.
  • -3 is completely ignored, and was previously used for a feature that is no longer supported.

 

Last edited Dec 16, 2014 at 9:52 PM by ronlo, version 65

Comments

No comments yet.