Skip to content

Latest commit

 

History

History
91 lines (69 loc) · 3.2 KB

README.md

File metadata and controls

91 lines (69 loc) · 3.2 KB

What is it?

CSSMin takes your CSS file and strips out everything that’s not needed — spaces, extra semicolons, redundant units, and so on. That’s great, but there are loads of programs that do that. A shell script could do that! So what makes CSSMin different?

When you deliver content over the web, best practice is to deliver it gzipped. CSSMin takes your CSS file, and optimises it for gzip compression. This means that there’s a smaller payload delivered over the wire, which results in a faster experience for your users. It does this optimisation by ensuring that the properties inside your selectors are ordered consistently (alphabetically) and in lower case. That way, the gzip algorithm can work at its best.

What this means in practice is that your gzipped CSSMin-ed files are significantly smaller than plain gzipped CSS, and noticeably smaller than files that have been compressed by other means (say, YUI).

What does it do?

  • Replaces font-weight values like 'bold' with their numeric counterparts;
  • Strips quotes wherever possible;
  • Changes as much of the contents to lowercase as possible;
  • Strips all comments from the source;
  • Removes unnecessary whitespace; and, most importantly,
  • Reorders the properties within your selectors alphabetically.

What does it support?

Just about everything! Nested properties benefit from compression (for example, -webkit-keyframes), whilst retaining the appropriate order. Prefixed selectors are moved to the top of the block, so that their non-prefixed counterparts will override them when the browser supports them. Most CSS hacks won't get stripped, but some involving comments might break.

Usage

  1. Compile the library with ant:

     # ant
    
  2. Run your CSS through it:

     # java -jar CSSMin.jar [input] [output]
    
  3. Profit!

Results

These are the results of compressing the main CSS file for one of the webapps I develop at work. Note that many of these compressors only offer an online service, which means that they can't easily be used as part of your general build process.

  Original size (bytes) Gzipped size (bytes)
Plain 81938 12291
YUI 64434 10198
LotteryPost 63609 10165
CSS Drive 69275 10795
CSSMin 63791 9896

Contributors

CSSMin was originally written, and is maintained by, Barry van Oudtshoorn.

Contributors:

License

CSSMin is licensed under the BSD License. See LICENSE for details.