« 19.09.07 | Main | 21.09.07 »

20.09.07

If You ever had to work with cascading style-sheets (CSS) which you didn't write entirely on Your own or with a CSS framework (such as YAML), then You probably asked yourself the same question as I did some days ago:
"Which classes are really used - and which could I delete without harm?"

An answer to this question I hoped to find on GoSquared.com, but the result was not really satisfying. The script had several bugs, making it nearly useless for me:

  • Only the first class / id in the css definition is taken into account
  • Multiple class names in the same class attribute were not recognised (resulting in "false positives")
  • Identical class / id will not report even if unused

But as it was pretty close to what I needed, I went ahead, corrected these bugs and implemented some improvements on my own:

  • Output prefixed with . respectively # to distinguish classes and id's
  • Support for multiple HTML / CSS pages (as in larger projects) added, use a comma-separated list as page parameter
  • Added an optional parameter "visual" which will make the script print the evaluated CSS and HTML to the browser window

As for a future version, one could integrate support for link type css definition <link rel="stylesheet" type="text/css" href="style.css"/> and probably its quite easy now to evaluate also inline CSS definitions. But as I won't use this functionality, I end the development here. Nevertheless everyone feel free to contribute!