473,608 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1887
"Rhino" <no************ ***********@nos pam.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.be llglobal.com>,
"Rhino" <no************ ***********@nos pam.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**********@e riclindsay.com> wrote:
In article <vz************ *****@news20.be llglobal.com>,
"Rhino" <no************ ***********@nos pam.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**********@e riclindsay.com> wrote in message
news:NO******** *************** *********@freen ews.iinet.net.a u...
In article <vz************ *****@news20.be llglobal.com>,
"Rhino" <no************ ***********@nos pam.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**********@e riclindsay.com> wrote in message
news:NO******** *************** *********@freen ews.iinet.net.a u...
$ 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************ ***********@nos pam.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
1358
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 being used. Some entire directories may be obsolete. Is there a way I can identify the unused code? Basically I need to locate Perl files that are not used by any other Perl file in a directory tree. Yours,
1
2614
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 difference is, AFAICS, is that id selectors can only be used once, whereas class selectors can be used repeatedly ? Is this the main differentiator ? Regards Tony B
4
4247
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 than the inner one. here's a self-contained example: <HTML><HEAD> <style type="text/css"> table.foo td { background-color:red; }
7
3379
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
2779
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 exporting subs and hashes and that the coding style in general best can be described as 'varied'. I could, to my surprise, not find any solution on CPAN.
32
5090
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 * 10^12) it's pretty efficient, it took 15 minutes to compute the first 1,000,000 primes.
9
2296
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 named after the SessionID. At Session_End, I do some cleanup and delete the "session folder". However, if the PC is rebooted before the session times out, the clean up never happens. So what I wanted to do isL: In my CleanUp method, check all...
5
4794
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
1748
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> <tr><td>.</td></tr> <tr><td>.</td></tr> </tbody> </table>
0
7987
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8472
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8464
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8324
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6805
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1318
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.