views:

6285

answers:

10

Any recommendations for a CSS minifier?

I’ll be rooting around Google and trying some out, but I suspected that the smart, proficient and curiously handsome StackOverflow community might have already evaluated the pros and cons of the heavyweights.

+19  A: 

The YUI Compressor is fantastic. It works on javascript and css. Check it out.

Buddy
Adding onto this, here is a Makefile which will download the YUI Compressor, pack your files, and minify them.http://github.com/balupton/jquery-sparkle/blob/9921fcbf1cbeab7a4f2f875a91cb8548f3f65721/Makefile
balupton
+8  A: 

There's also a .NET port of YUI Compressor which allows you to:-

  • intergrate the minification/file combining into Visual Studio post-build events
  • intergrate into a TFS Build (including CI)
  • if you wish to just use the dll's in your own code (eg. on the fly minification).
Pure.Krome
+3  A: 

I like Minify. In PHP and works with CSS or JavaScript.

artlung
A: 

If you want a web tool solution try Pretty Diff tool. http://mailmarkup.org/prettydiff/prettydiff.html

Couldn't even get it to recognize that I wanted to compress css - kept saying "this doesn't look like javascript" after I select css minification...
B T
+3  A: 

If you are looking for an online tool, try this: http://www.csscompressor.com/

miguelSantirso
I wish I could down vote this answer (its already too late after i upvoted it). I'm trying to compress my css and it breaks things. That isn't good at all. Warning to everyone out there, my guess is that unless you have pristine standards compliant css, it might break your shit!
B T
But, *shouldn't* *you* have pristine, standards compliant CSS?
Django Reinhardt
+3  A: 

If you use Python I would recommend slimmer which is probably not as fast as YUI Compressor but unlike csscompressor.com it doesn't choke on CSS hacks.

I'm biased since I wrote slimmer and I'm currently evaluating YUI Compressor to see how it handles hacks. An example of slimmer in action can be seen if you view the source of crosstips.org

Peter Bengtsson
+1  A: 

I've written an ultra fast CSS minifier in C#. The algorithm does not handle Javascript though. Thy this: http://www.ko-sw.com/Blog/post/An-Ultra-Fast-CSS-Minify-Algorithm.aspx.

Kerido
Nice-looking option. One query though: you said “According to the CSS specification, two types of strings are supported: single-quoted and double-quoted. My algorithm leaves the string intact, even if whitespace characters are found inside it... I just think that keeping the string unmodified is more intuitive and professional.” Surely any space characters that don’t add meaning should be removed, to make the output file as small as possible? Isn’t that the point of minification?
Paul D. Waite
Well, in my opinion this is surely right in a general case. But I consider strings a special case. It is up to the developer of the original CSS whether or not to remove meaningless whitespace from strings. The algorithm I'm showing simply follows the specification keeping the string unmodified.
Kerido
+1  A: 

If you're looking for something in PHP, here's the link:-

Fat-Free Minify

Although it's part of the PHP Fat-Free Framework, it can also be used stand-alone.

stillstanding
+1  A: 

I find that isnoop's CSS SuperScrub works very well. It can only handle direct links to CSS online though :/ You can get around that though by using your preferred pastebin service to hold the css code and just giving SuperScrub the raw link.

John
A: 

An online tool (much better than www.csscompressor.com which jacked my css up): http://www.cssdrive.com/compressor/compress.php does an excellent job.

B T