Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Combine Files & Compress

I want to be able to, at build-time, submit a group of CSS files and have the following done:

  • Combine all CSS files into one CSS file
  • Combine all overlapping selectors
  • Remove all comments
  • Remove unnecessary white space
  • Remove empty styles

I'm sure there are others, but this what I'm starting with.

This is the preference order of how I would like to access the tool:

  1. Remote Website
  2. Web Hosted Installed - same as my website (Debian/PHP 5.2.12)
  3. Local Machine Installed (Windows 7)

I saw CSS Compressor, but it doesn't seem to combine CSS files nor does it combine overlapping CSS selectors.

Thanks in advance.

like image 651
w0lf42 Avatar asked Oct 10 '22 15:10

w0lf42


1 Answers

I would recommend the YUI compressor since it is widely used and has a command line interface.

You should also consider making your build process automated so that you can build everything with a single command. If you don't want to use an existing build tool you could create a short .bat file for this kind of task.


First, combine your files:

type file1.css file2.css file3.css > combined.css

then pass it to the YUI compressor:

java -jar yuicompressor.jar combined.css > combined-min.css
like image 157
Martin Avatar answered Oct 13 '22 09:10

Martin