473,324 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Finding unused selectors?

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
6 1876
"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
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
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

"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
> "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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Noah | last post by:
I inherited a large perl project with many small perl files spread out over different directories. The project is an admin tool with a cgi interface. I suspect that many of the files are no longer...
1
by: Tony Benham | last post by:
I have been getting to grips with css recently (very slowly), and one area I have a problem is when to use class selectors or id selectors. Are there any guidelines when to use each type ? The key...
4
by: Andy Fish | last post by:
hi, I am using descendent selectors to format cells within a table according to the css class of the table. However, when using nested tables, it seems to pick up the outer matching rule rather...
7
by: ralphNOSPAM | last post by:
Is there a PHP script that can find unused variables? I'd like to 'clean up' my scripts. Thanks...
0
by: Kaare Rasmussen | last post by:
I'm looking for an easy way to find unused modules in a perl program. I can do it by hand, but it's slow, error prone and boring. The task is not made easier by the fact that some modules are...
32
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 *...
9
by: Laurent Bugnion | last post by:
Hi, I am wondering what is the best way to find out which ASP.NET sessions are still active. Here is the reason: I have a custom control which can upload files. It saves the files in a folder...
5
by: Jake K | last post by:
In VStudio 2005 is there an easy way to find unused methods? I have a application that has been restructures several times and I would like toremove any methos that is not used.
5
by: Nathan Sokalski | last post by:
I'm not sure if this is the right place to ask this question, but I wasn't sure where else to go. I have a table made of the following tags: <table class="myclass"> <tbody> <tr><td>.</td></tr>...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.