YUI Compressor Version 2.2 Now Available

This new version of the YUI Compressor supports stdin and stdout. This means that you can now call the YUI Compressor using the following command line:

java -jar yuicompressor-2.2.jar --type js < input.js > output.js

You can still use the following syntax as well:

java -jar yuicompressor-2.2.jar -o output.js input.js

This has three main consequences:

  1. All informational and error messages are now printed to stderr.
  2. If no input file is specified, the YUI Compressor defaults to stdin. In that case, you must specify the --type option because the YUI compressor has no way of knowing whether it should invoke the JavaScript or CSS compressor (there is no file extension to look at)
  3. If no output file is specified, the YUI Compressor defaults to stdout (in prior versions, it used to create a file named after the input file, and appended the -min suffix)

The other main feature brought by this new version of the YUI Compressor is the support for JScript conditional comments:

/*@cc_on
   /*@if (@_win32)
      document.write("OS is 32-bit, browser is IE.");
   @else @*/
      document.write("Browser is not 32 bit IE.");
   /*@end
@*/

Note that the presence of a conditional comment inside a function (i.e. not in the global scope) will reduce the level of compression for the same reason the use of eval or with reduces the level of compression (conditional comments, which do not get parsed, may refer to local variables, which get obfuscated) In any case, the use of Internet Explorer’s conditional comments is to be avoided.

Finally, a few improvements have been made to the CSS compressor.

Download version 2.2 of the YUI Compressor

12 thoughts on “YUI Compressor Version 2.2 Now Available

  1. David Bernard

    Nice news.
    yuicompressor-maven-plugin is updated => 0.5 and deployed (24H later for central repo).

    Suggestion for CSS compress / optimizer :
    * add an option to replace @import by real import/inclusion of css.

    Thx

  2. Jorge De Castro

    The support for conditional comments is awesome! This is great stuff, Julien

  3. Alexander

    There is a bug. Rule “opacity: 0.2″ transformed into “opacity.2″ (without colon).

  4. Pingback: YUI Compressor 2.2 Released » Chris Norton

  5. Sonny Gill

    Hi Julien,

    Very cool!
    I just started writing a build file for a webapp, and this is going to be incredibly handy.

    BTW, I don’t know if it is just me, but I can’t get the new syntax for invoking the compresser to work.

    On using -
    java -jar yuicompressor-2.2.jar -type js output.js
    the output is still sent to the std. out

    Regards,
    Sonny

  6. Julien Lecomte Post author

    @Sonny

    If you want to send the output to a file without using a redirection (which is what you seem to do), then you need to use the -o option.

  7. Sonny Gill

    Grrr..silly me.
    I am quite used to using redirecting input OR output, but seeing them used together like that made me think that input.js is an optional argument. My bad.

    I did use the -o option in the end.

    Incidentally, when using redirect, I get the following on std out or the output file -

    [INFO] Using charset MacRoman

    Looks like java.util logging output.
    I am using the terminal app in Mac OS with the default install of Java (1.5.0_07).
    Not a problem for me though.

    Thanks Julien.

  8. Julien Lecomte Post author

    @Sonny

    That informational message you are mentioning actually appears in the standard error. You can get rid of these messages by using something like the following (all on one line):

    java -jar yuicompressor-2.2.jar --type js
        < input.js > output.js 2 > /dev/null
    

    Regards

  9. Mike de Boer

    Dear Julien,

    First, I’d like to thank you for this fantastic piece of work! Very solid piece of software.

    I encountered an issue, however, in the CSS compressor:

    filter: chroma(color=”#FFFFFF”);

    …is compressed to…

    filter: chroma(color=”#FFF”);

    …which makes the filter break in IE. Lovely browser, ain’t it? It cannot handle hex values with less then six characters! There’s always an exception to the rule :)

    Regards

  10. Gerard

    David - “Suggestion for CSS compress / optimizer :
    * add an option to replace @import by real import/inclusion of css.”

    +1

Comments are closed.