Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DesignIt

macrumors member
Original poster
Aug 2, 2005
75
0
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
 
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.
 
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 :eek: :p
 
mnkeybsness said:
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.