Aug 27 2007

YUI Compressor Version 2.0 Now Available

Published by Julien Lecomte at 11:09 am under Web Development

I am very pleased to announce the release of version 2.0 of the YUI Compressor. In addition to fixing several bugs and implementing a few enhancements suggested by the community, I also integrated Isaac Schlueter’s regular expression based CSS minifier. Therefore, the YUI Compressor is now able to compress both JavaScript and CSS files (see the CHANGELOG for a full list of changes) And as always, keep the feedback coming!

Download version 2.0 of the YUI Compressor

36 Responses to “YUI Compressor Version 2.0 Now Available”

  1. Gilleson 28 Aug 2007 at 2:33 am

    Great work, however, i can’t seem to find his cssMinifier on the web. I would like to port his cssmin to PHP, if that is allowed by the author.

  2. [...] YUI Compressor 2.0 es otra aleternativa para comprimir los archivos Javascript… está basado en Java y Rhino. [...]

  3. Albert Kühneron 28 Aug 2007 at 3:21 am

    As far as I can see there’s a newline between the closing bracket “{” and the next css command:

    …}
    body{…

    Isn’t it possible to delete this line break for greater compression?

    Second one:

    url( ‘../images/default/grid/loading.gif’ )

    can be compresed to

    url(’../images/default/grid/loading.gif’)

    Albert

  4. Matjažon 28 Aug 2007 at 3:29 am

    Very nice !

    Keep up the good work !

  5. [...] Julien Lecomte keeps rev’ing his new YUI Compressor with a 2.0 release. [...]

  6. David Bernardon 28 Aug 2007 at 4:43 am

    Hi,

    Great news. I’m creating a maven2 plugin based on your tool. Because your jar isn’t available as a lib on a maven repository. I include the source (exclude the main) into the source of the Project. Can I publish it on a public Maven Repository ?

    (The plugin in under LGPL, your code under BSD and I credit you for your work (and link) in the doc).

    Regards

  7. Tane Piperon 28 Aug 2007 at 5:49 am

    Wicked! I now use your tool for all my JS, and now I can do it for CSS too - one of the ultimate tools for every web developer.

  8. Tom Espositoon 28 Aug 2007 at 7:18 am

    Wow. Nice work. Some of the best compression I’ve seen. I love it since I use YUI as well.

    Does anyone have sample code for compressing one or more directories of js and css files using a maven script?

  9. David Bernardon 28 Aug 2007 at 8:43 am

    To compress one or more directories (every js and css in resources and src/main/webapp) using a maven script I use :
    mvn net.sf.alchim:yuicompressor-maven-plugin:compress

    This the plugin/mojo I create, I wait Julien agrement before publish it (after 1 day is need to be present on maven central repo).

  10. Kris Zypon 28 Aug 2007 at 8:47 am

    Awesome, everything I asked for! Correct packaging, clean API, perfect! I will be integrating this into Resource Accelerate soon, so Java developers can have automatically compressed and gziped JS files with one simple J2EE filter.

  11. Kris Zypon 28 Aug 2007 at 8:59 am

    One more request… Could you provide an extra jar with just your com.yahoo.platform.yui.compressor.*.class files, so that it would be easier to mix and match different rhino (and jargs I guess) versions with different YUI Comp versions? Great work again, though.

  12. Julien Lecomteon 28 Aug 2007 at 9:20 am

    @Albert

    I will fix these in the next version (2.1) Stay tuned!

  13. Apostolos Tsakpinison 28 Aug 2007 at 10:03 am

    I would like to have the ability to pipe the source file and have the compressed output printed in stdout ( like the dojo compressor ).

    I also have an issue with v2.0 when I want to just replace the source file with the compressed version. I pass the -o flag with same file path but the result file is empty. It worked with v1.0.

    As for the CSS compressor, you could also omit the last [;] before the closing bracket [}] of each rule. That’ll save a lot of bytes.

  14. Julien Lecomteon 28 Aug 2007 at 10:09 am

    @ Apostolos

    Yes, these are things I need to fix for the next version. However, the last semi-colon before the closing curly of a css rule is actually important for some older browsers which crashed if these weren’t there (safari…)

  15. [...] can’t be used. I chose Julien Lecomte’s new YUI Compressor, which is currently at version 2.0, for this task. It should be noted that YUI-Compressor is slow and can’t be used for [...]

  16. Julien Lecomteon 28 Aug 2007 at 12:09 pm

    @David Bernard

    Sure, go ahead with the maven plugin. Let me know when it gets published.

  17. DPPon 28 Aug 2007 at 12:26 pm

    How about supporting Microsoft conditional comments like Dean Edwards packer does?
    I think it is the best way to detect IE.
    if(/*@cc_on!@*/false) alert(’ie’);

  18. KevinHon 28 Aug 2007 at 12:56 pm

    Looks great! Noticed a similar empty file result when you omit the –type flag and pass a file without .js or .css

    java -jar jars/yuicompressor-2.0.jar test.foo

    In v1.x this used to work. Easy workaround is to add the –type js flag.

  19. Julien Lecomteon 28 Aug 2007 at 1:15 pm

    @DPP

    Definitely a feature worth implementing!

    @Kevin

    That is the way the v2.0 was designed to be used.

  20. [...] Julien Lecomte’s YUI Compressor [...]

  21. David Bernardon 28 Aug 2007 at 1:49 pm

    OK, I publish the maven plugin.
    my repository : http://alchim.sourceforge.net/download/releases/
    It should available on central repo in 24H.

    For information about it :
    http://alchim.sourceforge.net/yuicompressor-maven-plugin/overview.html

    Feedbacks are welcome.

    @Julien
    For the next version of the plugin, I want a more integrated error reporting, so I start some modification in your code (replace use of stdout by ErrorReporter, possibility to inject ErrorReporter in constructor). How to send you the modification ?

  22. Julien Lecomteon 28 Aug 2007 at 1:54 pm

    @David

    You don’t have to use stderr or stdout. Look at the constructor JavaScriptCompressor and CssCompressor: they take 2 PrintStream objects in parameter. The first one is used as the standard output, and the second one is the error output.

  23. David Bernardon 28 Aug 2007 at 2:19 pm

    It’s more efficient to provide an ErrorReporter, where I could set the filename currently processed, and where I could count warning and error, than decorate a PrintStream and parse the string to print.

  24. David Bernardon 28 Aug 2007 at 2:33 pm

    You could see the changeset :
    http://alchim.sourceforge.net/hg/yuicompressor-maven-plugin/rev/be8521620c20

    With the change I could have :

    [INFO] [yuicompressor:compress]
    [INFO] uni-form-generic.css (4902b) -> uni-form-generic-min.css (1625b)[33%]
    [INFO] uni-form.css (8431b) -> uni-form-min.css (3435b)[40%]
    [WARNING] /home/dwayne/work/oss/alchim-projass/src/main/webapp/static/uni-form/js/highlighter.js:line -1:column -1:Found an undeclared symbol: i
    Highlighter.settings.field_class);for(i —> = highlighter-min.js (1625b)[50%]
    [WARNING] /home/dwayne/work/oss/alchim-projass/src/main/webapp/static/uni-form/js/uni-form.jquery.js:line -1:column -1:Found an undeclared symbol: $
    ;});});};$ —> ( uni-form.jquery-min.js (674b)[53%]
    [INFO] style.css (11620b) -> style-min.css (8474b)[72%]
    [INFO] buttons.css (2513b) -> buttons-min.css (1227b)[48%]
    [INFO] grid.css (5012b) -> grid-min.css (2003b)[39%]
    [INFO] reset.css (1164b) -> reset-min.css (642b)[55%]
    [INFO] typography.css (5136b) -> typography-min.css (1800b)[35%]
    [INFO] print.css (1568b) -> print-min.css (631b)[40%]
    [INFO] screen.css (1035b) -> screen-min.css (103b)[9%]
    [INFO] navbar.css (653b) -> navbar-min.css (460b)[70%]
    [INFO] total input (46508b) -> output (22699b)[48%]
    [INFO] nb warnings: 2, nb errors: 0
    [INFO] ————————————————————————
    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] wrap: warnings during compression of js and css! (see log)

  25. Julien Lecomteon 28 Aug 2007 at 2:41 pm

    @David

    OK, I’ll make some changes to the next version of the compressor.

  26. links for 2007-08-28 « napyfab:blogon 28 Aug 2007 at 4:37 pm

    [...] Julien Lecomte’s Blog » YUI Compressor Version 2.0 Now Available (tags: compression compressor css javascript release yui yahoo news web development) [...]

  27. Liam Clancy (metafeather)on 29 Aug 2007 at 12:46 am

    With ref to the article here: http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/

    If you want to use the supplied web page to enter JS code; depending on your server/php.ini setup you may need to detect for “Magic Quotes” to stop the posted JS code from being escaped before compression (and throwing errors in the YUICompressor)

    This does not affect the command line version.

    Regards

    Liam

  28. Arthur Blakeon 29 Aug 2007 at 7:19 am

    The CompressorRater has been updated for YUI Compressor 2.0. I’ve also posted some stats on the compression levels achieved in several popular JavaScript libraries.

    The CompressorRater is a web application that lets you dynamically compare the compression levels of several popular javascript compressors, both with and without the affects of gzip compression:

    http://compressorrater.thruhere.net/

  29. The Doctor Whaton 29 Aug 2007 at 11:49 am

    SUGGESTION: Please make the ‘-o’ option understand stdout. The warnings and errors should go to stderr.

    Thanks for doing this. BTW: How is the CSS done? Is it parsed as well, or is it regex based?

    Ciao!

  30. The Doctor Whaton 29 Aug 2007 at 12:05 pm

    SUGGESTION:

    The warnings don’t include line numbers, which makes finding the warnings a little difficult.

  31. The Doctor Whaton 29 Aug 2007 at 12:09 pm

    Version: 2.0
    Command line: –warn –charset utf-8 –type css
    Input File:
    /* comment */
    .class1 { font-weight: bold; }
    .class2 { color: lime; }

    The rendered output includes a space character as the first character. I’m guessing from the comment.

  32. The Doctor Whaton 29 Aug 2007 at 12:12 pm

    SUGGESTION:

    Allow multiple file names to be included, to be appended in order before processing.

  33. Julien Lecomteon 29 Aug 2007 at 12:45 pm

    @Christian (aka The Doctor What…)

    I will add your first suggestion to my list of improvements for a future version.

    Your second comment mentions a bug that has been fixed in the version 2.1 now available for download on this site.

    Your last suggestion is beyond the scope of this tool.

    Regards

  34. Jawad Anwaron 21 Apr 2008 at 3:47 pm

    Hello Julien,
    I downloaded the 3 jars and getting it to run in Eclipse IDE using the command as shown in readme but keep getting this ‘Unable to access jarfile yuicompressor-2.3.5.jar’ - can you please advice - thanks in adv.

  35. Julien Lecomteon 21 Apr 2008 at 3:52 pm

    @Jawad,

    I’m not an Eclipse user, can’t help you here, sorry.

  36. Jawad Anwaron 21 Apr 2008 at 4:05 pm

    Please ignore my last comment. I figured it out..it was a path issue…
    sorry.
    Works great.
    Thanks