YUI Compressor Version 2.0 Now Available

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 thoughts on “YUI Compressor Version 2.0 Now Available

  1. Gilles

    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. Pingback: YUI Compressor 2.0… en lanzamiento :

  3. Albert Kühner

    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. Pingback: Ajax Girl » Blog Archive » Keep on squeezing with YUI Compressor

  5. David Bernard

    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

  6. Tane Piper

    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.

  7. Tom Esposito

    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?

  8. David Bernard

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

  9. Kris Zyp

    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.

  10. Kris Zyp

    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.

  11. Apostolos Tsakpinis

    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.

  12. Julien Lecomte Post author

    @ 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…)

  13. Pingback: Improvements for Madman’s Website » Chris Norton

  14. DPP

    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’);

  15. KevinH

    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.

  16. Pingback: Dean Edwards: Notes on JavaScript Compression

  17. David Bernard

    OK, I publish the maven plugin.
    my repository :
    It should available on central repo in 24H.

    For information about it :

    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 ?

  18. Julien Lecomte Post author

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

  19. David Bernard

    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.

  20. David Bernard

    You could see the changeset :

    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)

  21. Pingback: links for 08-28 « napyfab:blog

  22. Liam Clancy (metafeather)

    With ref to the article here:

    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

  23. Arthur Blake

    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:

  24. The Doctor What

    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!

  25. The Doctor What

    SUGGESTION:

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

  26. The Doctor What

    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.

  27. The Doctor What

    SUGGESTION:

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

  28. Julien Lecomte Post author

    @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

  29. Jawad Anwar

    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.

  30. Jawad Anwar

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

Comments are closed.