PDA

View Full Version : CSS program question?




DesignIt
Dec 19, 2005, 11:52 AM
Does anybody know of a program that will go thru a style sheet and remove any unused styles?

That would be a helpful program. :D



mnkeybsness
Dec 19, 2005, 01:59 PM
How would it know what is used and what is not?

A good stylesheet should only be written to include styles that are used on your pages and your layout should reuse styles as needed so that you don't end up with 4 classes that do the same thing.

It's all a matter of planning.

munkle
Dec 19, 2005, 02:29 PM
Of course ideally that would be the case but a lot of sites (especially blogs) aren't built from scratch by people knowledgeable in CSS but hacked from a pre-supplied template...I may or may not be speaking from experience :o :p

floyde
Dec 19, 2005, 03:03 PM
How would it know what is used and what is not?

It could read the whole HTML looking for the "class" or "id" (on divs) attributes, and then it could match it to the CSS stylesheet. I haven't heard of such a program though.

Josh
Dec 19, 2005, 03:23 PM
You could set up a simple shell script that would search for (using grep) all instances of <div id="*"> and <div class="*"> within the HTML file, then have it replace <div id="*"> with #*, and <div class="*"> with .*, and save that as a new document.

Then you'd pretty much just have to compare the two on your own. The script could search for common instances, but it would have no idea of knowing what is a propery and what is a name, so you'd be left with only the names of the ids and classes. I guess that could then be used to help you know which ones are safe to delete, though.