By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

Finding unused selectors?

P: n/a
What's the simplest way to determine which, if any, of my selectors are not
needed in a given stylesheet?

I have a small number of HTML pages that share two stylesheets; one
stylesheet is for display purposes and one is for printing. I suspect that
some of the selectors in my stylesheet are no longer needed due to deletions
of parts of the HTML pages and would like to remove those selectors from my
stylesheets. But I'd like to avoid a manual inspection process to determine
which selectors can be removed since it would be quite easy to mess that up.

I suspect that there is some sort of automated process - maybe a freeware
tool? - for finding all the unused selectors in a given CSS, given a list of
the names of the HTML files using it. If that is right, I'd like someone to
tell me how to accomplish that process.
--
Rhino
Jan 8 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Rhino" <no***********************@nospam.com> wrote:
I suspect that there is some sort of automated process - maybe a freeware
tool? - for finding all the unused selectors in a given CSS


Topstyle sort of[*] has a function to report unused id's and classes,
payware though.

* It cannot handle multiple classes in the HTML.

--
Spartanicus
Jan 8 '06 #2

P: n/a
In article <vz*****************@news20.bellglobal.com>,
"Rhino" <no***********************@nospam.com> wrote:
What's the simplest way to determine which, if any, of my selectors are not
needed in a given stylesheet?


I will shortly have a similar problem, but with about 400 pages and
about a dozen style sheets, all totally out of control. While I don't
have a solution yet, it does occur to me that as a starting point,
extracting all the id and class names from all the HTML pages would be a
good starting point for comparing with those in the CSS. I just tried
this:

$ grep -h class=\" *.htm | awk -F "<|>" '{print $2}' | sort | uniq

and although it has a few spurious classes in it, that is doing most of
the HTML side of the extraction of classes from one directory of files.
If you happen to have Unix style command line tools on your computer (I
am using a Macintosh) that may be a worthwhile starting point.

--
http://www.ericlindsay.com
Jan 9 '06 #3

P: n/a
In article <NO********************************@freenews.iinet .net.au>,
Eric Lindsay <NO**********@ericlindsay.com> wrote:
In article <vz*****************@news20.bellglobal.com>,
"Rhino" <no***********************@nospam.com> wrote:
What's the simplest way to determine which, if any, of my selectors are not
needed in a given stylesheet?

$ grep -h class=\" *.htm | awk -F "<|>" '{print $2}' | sort | uniq


on second thoughts, you don't need awk, and you can recurse through your
file tree.
$ grep -h -r --include=*.htm* -o id=\".*\" * | sort | uniq

--
http://www.ericlindsay.com
Jan 9 '06 #4

P: n/a

"Eric Lindsay" <NO**********@ericlindsay.com> wrote in message
news:NO********************************@freenews.i inet.net.au...
In article <vz*****************@news20.bellglobal.com>,
"Rhino" <no***********************@nospam.com> wrote:
What's the simplest way to determine which, if any, of my selectors are
not
needed in a given stylesheet?


I will shortly have a similar problem, but with about 400 pages and
about a dozen style sheets, all totally out of control. While I don't
have a solution yet, it does occur to me that as a starting point,
extracting all the id and class names from all the HTML pages would be a
good starting point for comparing with those in the CSS. I just tried
this:

$ grep -h class=\" *.htm | awk -F "<|>" '{print $2}' | sort | uniq

and although it has a few spurious classes in it, that is doing most of
the HTML side of the extraction of classes from one directory of files.
If you happen to have Unix style command line tools on your computer (I
am using a Macintosh) that may be a worthwhile starting point.

As it happens, I'm using Windows XP. I have access to a Linux server and
could, in a pinch, transfer my pages over there in order to grep them but
I'm hoping someone can recommend a tool that will work in Windows before I
resort to transferring files.

Rhino
Jan 9 '06 #5

P: n/a
> "Eric Lindsay" <NO**********@ericlindsay.com> wrote in message
news:NO********************************@freenews.i inet.net.au...
$ grep -h class=\" *.htm | awk -F "<|>" '{print $2}' | sort | uniq

Rhino wrote: As it happens, I'm using Windows XP.


You caould install MinGW (and some more libraries) and then use the
stuff proposed by Eric.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Jan 9 '06 #6

P: n/a
On Sun, 8 Jan 2006 12:01:43 -0500, "Rhino"
<no***********************@nospam.com> wrote:
What's the simplest way to determine which, if any, of my selectors are not
needed in a given stylesheet?


"Unused" are generally less of a problem than "duplicates" in this
context.
Jan 9 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.