Sep 18 2007

YUI Compressor Version 2.2 Now Available

Published by Julien Lecomte at 4:15 pm under Web Development

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 responses so far

12 Responses to “YUI Compressor Version 2.2 Now Available”

  1. David Bernardon 19 Sep 2007 at 1:20 am

    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 Castroon 19 Sep 2007 at 4:29 am

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

  3. Alexanderon 19 Sep 2007 at 4:49 am

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

  4. [...] is a new 2.2 release of Julien Lecomte’s fantastic YUI Compressor for minifying JavaScript. This version has some [...]

  5. Julien Lecomteon 19 Sep 2007 at 6:52 am

    @Alexander

    Thanks for reporting this, I already fixed it.

    Regards

  6. Sonny Gillon 19 Sep 2007 at 8:09 am

    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

  7. Julien Lecomteon 19 Sep 2007 at 8:28 am

    @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.

  8. Sonny Gillon 19 Sep 2007 at 11:21 am

    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.

  9. Julien Lecomteon 19 Sep 2007 at 11:30 am

    @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

  10. Mike de Boeron 25 Sep 2007 at 3:30 am

    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

  11. Julien Lecomteon 25 Sep 2007 at 11:14 am

    @Mike

    Thanks for the bug report. I just fixed it in version 2.2.1 now available for download.

    Regards

  12. Gerardon 21 Jan 2009 at 6:29 pm

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

    +1

Comments RSS

Leave a Reply