cssmin.js

cssmin.js is a JavaScript port of YUICompressor's CSS minifier.

The motivation

Minifying CSS helps reduce file sizes and makes your pages faster and your users happier. YUICompressor is cool but is written in Java, which can be a blocker for some folks - you know JVM, command line, classpaths... No more excuses, now you have a simple light JavaScript version. And as you know, JavaScript is everywhere, so you can run it however you want, integrate with your editor and so on.

The links

The integration

If you want to integrate the library into your environment, it's really easy. It's just one file with one function in it. So, just a simple function call:

var result = YAHOO.compressor.cssmin(input_css_code);

The credits

Julien Lecomte - creator of YUICompressor
Isaac Schlueter - he maintains the YUICompressor and is the author of the original cssmin utility which was ported to Java by Julien.

Ha, what about a quiz? Guess the language of Isaac's original cssmin and I'll send you a free copy of Even Faster WebSites and I'll sign my chapter. Seriously.

UPDATE: For Ruby folks, there's a Ruby port from the Ryan Grove.

This entry was posted on Wednesday, September 23rd, 2009 and is filed under CSS, JavaScript, performance, yui. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

Somewhat related posts

7 Responses to “cssmin.js”

  1. Greg Schechter Says:

    I’m going to guess Isaac wrote it in PHP

  2. Twitter Trackbacks for cssmin.js / phpied.com [phpied.com] on Topsy.com Says:

    [...] First Tweet 15 minutes ago stoyanstefanov Stoyan Stefanov Highly Influential New blog post: cssmin.js http://www.phpied.com/cssmin-js/ view retweet [...]

  3. Stoyan Says:

    heh, the shortest contest ever :)

    Greg, send me your mailing address to ssttoo at gmail

  4. P.Sorokin Says:

    Add to the end for correct work in IE6
    //:first-letter and :first-line for IE6
    css = css.replace(/:first-letter+/g, “:first-letter “);
    css = css.replace(/:first-line+/g, “:first-line “);

  5. Stoyan Says:

    Thanks P.Sorokin!

  6. CSS munging - a FAILed experiment / phpied.com Says:

    [...] phpied.com Stoyan’s blog about (x)html, ajax, bookmarklets, browsers, css, firebug, javascript, json, mdb2, mysql, pear, performance, php, phpbb, tools, yslow, yui, writing, music,… life and everything. « cssmin.js [...]

  7. Steven Paul Says:

    I need a perl version of this script, for server side optimization…

Leave a Reply