On 10 Jan, 20:42, fleem...@comcast.net wrote:
Over the course of building a very large site, I've wound up with an
enormous style sheet containing plenty of superfluous styles. Is there
a tool that can recognize which styles are not being used
In the full and generalised case, no. It's a computationally difficult
problem. It's _impossible_ to do so for a stylesheet alone, as it
requires knowledge of the HTML to which it's being applied.
As a quick start though, try using a simple CSS validator, like the
W3C online one. This will give you a "normalised" rendition of the CSS
that's usually a good starting point. Where the CSS contains lots of
simple verbosity and literal duplication, then this can be useful.
The real problem though is more difficult. You will typically have
much CSS that repeats rules (or at least properties) but applies them
through different selectors. It's not ppossible to simplify this
automatically, as the CSS _is_ actually different. Only by applying
external knowledge of the HTML it's applied to (a HTML meta-structure
for the site) is it even _possible_ to recognise what's superfluous
duplication.
As an example, it's commonly-seen bad practice to apply CSS rules to
an <lielement, especially when there's a class repeated onto each
<litoo. A better CSS structure is to re-code this to style the <ul>
and then inherit (font settings etc. would inherit happily, but
obviously box-sizing couldn't), or even to apply the class to the <ul>
element and use selectors of the form ul.foo li {} instead. Making
these changes though requires an overall view of the problem, right
back to the HTML meta-structure level. It's not something you can
expect a simple dupe-stripping script on the CSS alone to achieve.
IMHE, it's very difficult to improve complex existing CSS. The trick
is to structure and design carefully from the outset. Refactoring it
afterwards is hard!