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
 

mnkeybsness

macrumors 68030
Jun 25, 2001
2,511
0
Moneyapolis, Minnesota
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

macrumors 68030
Aug 7, 2004
2,580
1
On a jet plane
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
 

floyde

macrumors 6502a
Apr 7, 2005
808
1
Monterrey, México
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.
 

Josh

macrumors 68000
Mar 4, 2004
1,640
1
State College, PA
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.