5

Possible Duplicate:
How do I identify and eliminate unused CSS styles from my bloated stylesheet?

I have a html page and a huge CSS file that has about 900 style entries. I tried to clean it with Dust-Me and it found about 700 unused selectors. So, I think I can just go crazy removing these selectors from the list manually. Is there a way to remove them automatically?

Community
  • 1
  • 1
Denis
  • 53
  • 3

1 Answers1

8

Identifying unused CSS selectors using tools such as Dust-Me have some degree of error associated with them. For example, does it reliably identify a style referenced in dynamically created HTML - as might be done through JavaScript? The creators of Dust-Me may have been aware of this sort of pitfall and are actually protecting you by not offering to clean-up your CSS files.

The problem with identifying unused elements is that one has to make the assumption that because a usage was not found the element is unused. This is often a poor assumption. The site may not have been fully spidered resulting in missing references. Or, a dynamically created reference was not "visible" to the tool. In either case, automatically removing a CSS selector because some tool did not find a reference to it is a very large leap of faith - one that most likely will get you into trouble.

I recommend taking their generated list and doing the job by hand – very carefully!

NealB
  • 16,670
  • 2
  • 39
  • 60