In at least one major project which I worked on so far I have managed to successfully utilise CleanCSS within development process. CleanCSS is based on CSS Tidy.
Main reason: it can reduce CSS file size by 10-50% (before GZipping or minifying), without affecting page styles and design in any negative way (if used properly and with understanding of its weaknesses)!
Other reasons for using CleanCSS:
- It’s quick, automated and easily accessible on-line
- It beautifies the code making it easier to read
- It can order properties in alphabetical order
- It highlights invalid CSS declarations bringing about awareness of the overall validity of CSS file
- Can remove CSS comments if necessary
- Support for 5 levels of compression (default being ‘medium’ which is a balance between size and readability)
Known weaknesses:
- Sorting properties can cause problems if IE _ hacks are used within the stylesheet where the tool will put the _ hack first in the declaration order, which is often not desired
- We have also observed it converts zoom: 1 to zoom:1px which is easily rectifiable by doing a search and replace, as are other known problems like the _ hack issue
How to utilise within a team:
There are probably two main ways to utilise CleanCSS within the development process:
Ongoing utilisation would make use of the tool, say, once a week to clean the CSS files regularly and keep them down in size throughout the development process.
I would advise this method as it shows developers throughout the development process how ‘lean’ their development is as well as points out any potential subtle issues with using the tool early on, rather than at the last minute before site launch.
One-off utilisation would mean that CleanCSS would be run on all CSS files just before the launch of a web site in order to decrease CSS file size as much as possible so site can run as optimally as possible regarding CSS.
This means that slightly less time is consumed optimising CSS files regularly and having to remember to use the tool once a week, but it could be a little more ‘dangerous’ as some subtle issues might creep in.
My final thought on the question of ‘do I want my CSS files to be up to 50% smaller in size without jumping through major hoops in order to achieve it?‘. The answer is: ‘Yes please!‘.