PDA

View Full Version : Command-line CSS compressor/minifier?


Wyatt
2010-02-22, 21:07
I've been experimenting with LESS CSS (http://lesscss.org) this evening, and I really like it. The syntax is smart, and I can already see how this could make a huge impact on my Web design workflow. I already code all my stylesheets by hand, and this seems like a natural evolution for my design process.

There's one glaring problem, though: The resulting CSS is pretty bloated. CSS Compressor (http://www.csscompressor.com/) seems to do a pretty good job cleaning it up, but a Web-based compressor/minifier seems like an unnecessary extra step in my workflow. Yes, I know I can just skip this step until the end, but since I'm compiling the .less file from terminal anyway, it would be great if I could build a script that both compiled the .less file and compressed the resulting .css file.

Do any of you know of a command-line CSS minifier that I could use as a component to a script? Of course, I'll be happy to share my final script. :)

[edit] Something PHP- or Ruby-based would be fine, too. Anything I can run in Terminal works for me. :)

ddelco
2010-02-25, 18:16
AFAIK, YUI compressor is popular.

Alternatively, I don't know how attached you are to LESS, but just a heads up that Sass (http://sass-lang.com/) and Compass (http://compass-style.org/) can be configured to automatically output minified CSS.

Wyatt
2010-02-25, 19:46
YUI Compressor is nice. I tried it out, but I have one problem with it: It doesn't combine identical rules. Here's an example:


h3 {
color: black;
}
h2 {
color: black;
}


Compressor wouldn't combine those. Otherwise, I like it quite a bit. And this gets to the frustrating thing about LESS. If you combine the rules initially, LESS actually separates them as it compiles. If it wasn't for that fact, I could easily use Compressor to complete my workflow. For now, I'm using the online compressor I linked above. It does everything I want it too, but it would be nice to be able to automate this.

I looked at Saas (and Compass, which uses Saas) before I picked LESS. My problem with Saas is that it doesn't use standard CSS syntax. I wanted to feel like I was adding features to a language I've been using for years, not learning a new one. It does have nice features, but I'm willing to deal with the tradeoffs with LESS just to keep standard syntax.

ddelco
2010-03-01, 14:02
Yeah, I haven't used it for CSS for a long time since I generally use Sass, but my understanding is that it's what most people use.
I looked at Saas (and Compass, which uses Saas) before I picked LESS. My problem with Saas is that it doesn't use standard CSS syntax. I wanted to feel like I was adding features to a language I've been using for years, not learning a new one. It does have nice features, but I'm willing to deal with the tradeoffs with LESS just to keep standard syntax.
FWIW, because of the popularity of this aspect of LESS, the next version of Sass will basically be a superset of CSS, meaning it will also support standard bracketed syntax. A lot of the work has already been done in the scss branch (http://github.com/nex3/haml/tree/scss). Not that that really helps you at the moment, though.