views:

605

answers:

3

i need to compress my css as part of my ant build. i noticed that csstidy does this, but it would not be easy to include this in my ant build because i would need to use a different binary on different platforms.

so, is there a java css compressor that people use?

+7  A: 

Check out the Yahoo YUI compressor.

It compresses CSS as well as Javascript, and it's written in Java.

Edit: You should be using some sort of HTTP compression as well, like mod_deflate or mod_gzip.

Greg
A: 

the reason i want to compress the css: i know that csstidy for example, will look at the content of the css, and combine styles etc in order compress, plain gzip wont do that for me. another reason, is to obfuscate http compression is well and good, but does not accomplish the said goals.

mkoryak
CSS, unlike JavaScript, is not interpreted as such, so you can't obfuscate it. That is, if a selector is changed from .myClass to .a, it's no longer going to match. YUI does not evaluate CSS like csstidy, but it still saves some bytes over non-compressed code.
Andrew Hedges
+1  A: 

I recently released CSS Compressor. It's a code fork of YUI Compressor, but adds more compression enhancements that make it more similar to csstidy, particularly with regards to grouping selectors that share the same rules. Obviously it's Java, and can be called via the command-line or used as a library within your own Java app.

arooaroo