Comparing YUI Compressor and slimmer

17 November 2009   5 comments   Python

Mind That Age!

This blog post is 9 years old! Most likely, its content is outdated. Especially if it's technical.

YUI Compressor apparently supports compressing CSS. Cool! I had to try it and what's even more cool is that it's the only other CSS minifier/compressor that doesn't choke on CSS hacks (the ones I tried). The only other CSS minifier/compressor is my very own slimmer. So, let's see what the difference is.

Running the YUI Compressor 10 times on a relatively small file takes 0.3 seconds on average. Running the same with python 2.6 and slimmer.css_slimmer takes 0.1 seconds on average. I think most of this time is spent loading the jar file than the actual time of running the compression.

Here's how I ran yuicompressor:

$ time java -jar yuicompressor-2.4.2.jar --type css tricky.css > compressed.css

And for slimmer I first had to write a script:

from slimmer import css_slimmer
import sys
print css_slimmer(open(sys.argv[1]).read())

And run it like this:

$ time python tricky.css > slimmed.css

If part of a build system, 0.3 or 0.1 seconds don't matter. YUI Compressor has the added advantage that it's popular which means many eyes on it for submitting bug reports and patches. However, if you're already in Python and don't want to depend on manually downloading the jar file and running a subprocess then slimmer is probably a better choice.


Steve Lacy
I think you left out Google's Closure compiler, which explicitly states "The Closure Compiler reduces the size of your JavaScript files and makes them more efficient, helping your application to load faster and reducing your bandwidth needs."
Steve Lacy
Whoops, you're talking about CSS, not JavaScript. Should have read the post. D'oh.
Carl Meyer
Hey Peter - might want to fix the note on slimmer's PyPI page that proudly claims "still maintained in 2008." It no longer gives the impression of up-to-dateness it might once have done ;-)
Peter Bengtsson
Thanks for noticing. Done
Would you post the "tricky.css"? Wonder ig yuicompressor and slimmer will actually cope with any css hack out there (especially syntactically invalid ones... ;). That would be nice, thanks
Thank you for posting a comment

Your email will never ever be published

Related posts

Those Crazy Chinese 16 November 2009
Orphaned Land - Jewish Muslim Metal 08 December 2009
Related by Keyword:
Advanced Closure Compiler vs UglifyJS2 20 January 2016
How to test if gzip is working on your site or app 20 August 2015
HTML whitespace "compression" - don't bother! 11 March 2013
The awesomest way possible to serve your static stuff in Django with Nginx 24 March 2010
Comparing jsmin and slimmer 17 September 2009
Related by Text:
HTML Tree on Hacker News 18 May 2014
YouTube - Nigella's XXXmas 19 December 2008
How and why to use django-mongokit (aka. Django to MongoDB) 08 March 2010
How to track Google Analytics pageviews on non-web requests (with Python) 03 May 2016
hashin 0.7.0 and multiple packages 30 August 2016