Friday, July 6th, 2007p>Tom Armitage has written a simple tool that is immediately useful to anyone working with CSS. The CSS Redundancy Checker is a Ruby script that will take CSS rules, and a set of HTML files, and will tell you what you aren’t actually using:
css-redundancy-checker.rb [cssfile] [directory of html files OR .txt file listing urls to use]
When youâ€™re writing HTML, over time, your CSS files begin to fill up a lot. If youâ€™re working on a large project, you might even end up with several people contributing to the CSS file, not to mention refactoring each otherâ€™s work. The result is a directory full of HTML files, and a very large CSS file.
What tends to happen is that not ever selector in the CSS file actually applies to your HTML; many are rendered redundant by refactoring, or by changes in HTML. But when youâ€™ve got a 70k+ CSS file, itâ€™s not easy to check precisely which selectors arenâ€™t in use any more.
Enter the CSS Redundancy Checker. Itâ€™s a very simple tool, really. You pass in a single css file, and either a directory of HTML files, or a .txt file listing URLs (one to a line). It then proceeds to look at each file in turn, and at the end, list all the selectors in your css file that arenâ€™t used by any of the HTML files.