"Use efficient CSS selectors" ?

User 404575 Photo


Registered User
887 posts

My site is http://www.ColoradoProcessServers.net using Wordpress and Hostgator.

http://gtmetrix.com/reports/coloradopro … t/yp3BiAWH

says:

http://coloradoprocessservers.net/wp-co … /style.css has 2 very inefficient rules, 2 inefficient rules, and 0 potentially inefficient uses of :hover out of 26 total rules.

Very inefficient rules (good to fix on any page):

#wrapper table #header #information h2 Tag key with 4 descendant selectors
#wrapper table #header #information h4 Tag key with 4 descendant selectors

Inefficient rules (good to fix on interactive pages):

#wrapper #footer p a Tag key with 3 descendant selectors
#navcontainer ul li Tag key with 2 descendant selectors

I haven't the first clue what all that means and how to fix it. I'm just not familiar enough yet, with CSS and tables and all that. I'm pretty basic with code.

Melissa Rhiannon
OS Windows 10
User 184085 Photo


Ambassador
1,707 posts

I don't know what they mean either, but it gave my site a 'F' rating, but I'm not worried :)
Volunteering to help :)
http://www.tbaygeek.ca
My HTML play area
http://www.tbaygeek.ca/test/
User 404575 Photo


Registered User
887 posts

Mine started out a "C" and I've been tweaking the things I could understand or learn about, but this is one of the last ones that I don't understand.
Melissa Rhiannon
OS Windows 10
User 404575 Photo


Registered User
887 posts

Ok, from what I'm able to gather... I have this as a line in my style.css:

#wrapper table #header #information h2{font-size:18px;vertical-align:top;top:0px;padding-top:0;font-style:italic;font-weight:bold;font-family:arial;}

It apparently creates a distinct style, padding etc for
the wrapper table - header - information

and they're saying that this is an inefficient way of specifying that, because when the browsers read it all, they have to parse it somehow, which slows things down.

But I don't even have much of an idea what's happening here, yet alone how to improve it.

I found this: http://code.google.com/speed/page-speed … ering.html

Does this make sense to any of you?

Melissa Rhiannon
OS Windows 10
User 187934 Photo


Senior Advisor
20,271 posts

david wilson wrote:
I don't know what they mean either, but it gave my site a 'F' rating, but I'm not worried :)

I'm not either,
These speed sites give a false hope. They aren't going to tell you how many people will visit.;)
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 122279 Photo


Senior Advisor
14,649 posts
Online Now

Melissa,
What it means is that you probably have too many selectors sharing the same rules. E.g.
#wrapper table #header #information h2{font-size:18px;vertical-align:top;top:0px;padding-top:0;font-style:italic;font-weight:bold;font-family:arial;}

This is the rules for the h2 tag inside the div information - inside the div header - inside a table - inside the div wrapper The inefficency lies in that the css parser on the server has to wade through all these page elements to find out how to display the h2 tag. If you have h2 tags elsewhere, say just inside the table, that have to be displayed differently, you just write table h2 {....}. But if those h2 tags are the only ones in the whole site, if you never use them outside the infomation div, it's enough to write
h2{font-size:18px;vertical-align:top;top:0px;padding-top:0;font-style:italic;font-weight:bold;font-family:arial;}

In this rule:
#wrapper{width:980px;border:0px solid #000000;height:auto;left:auto;right:auto;margin-left:auto;margin-right:auto;clear:both;background-color:#FFF;padding-top: 5px;}

the wrapper itself is being styled, but in all other cases you can at least remove the '#wrapper' from the rules, as nothing is going to be placed outside the wrapper anyway. Then you'll have to check what else you can remove.

Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 404575 Photo


Registered User
887 posts

Thanks Inger!

I just removed #wrapper table from the beginning of the h2 and h4 lines and the score on that section went from B89 to A98 , with no apparent negative effect on the site pages!

Yeah! :D

Now it appears to be saying that I can remove the #header from the
#header #information h2... and h4 lines too, and fix all of it.
Melissa Rhiannon
OS Windows 10
User 122279 Photo


Senior Advisor
14,649 posts
Online Now

Good that you were able to improve it! :)

You can safely remove the #wrapper from these lines too:
#wrapper a:link, a:visited{color:#0000be;text-decoration:underline;}
#wrapper a:hover{color:#00a;}
...

#wrapper #footer p a{font-size:14px;font-style:italic;color:#0000be;text-decoration:none;font-family:arial;}
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 184085 Photo


Ambassador
1,707 posts

Eric Rohloff (Rolly) wrote:
david wilson wrote:
I don't know what they mean either, but it gave my site a 'F' rating, but I'm not worried :)

I'm not either,
These speed sites give a false hope. They aren't going to tell you how many people will visit.;)


exactly but they do get to vacuum up a tone of info from their clients :)
Volunteering to help :)
http://www.tbaygeek.ca
My HTML play area
http://www.tbaygeek.ca/test/
User 463058 Photo


Ambassador
1,086 posts

Melissa Brookstone wrote:

Very inefficient rules (good to fix on any page):

#wrapper table #header #information h2 Tag key with 4 descendant selectors
#wrapper table #header #information h4 Tag key with 4 descendant selectors


Because ID's are unique, there should only be one element on the page called #information, so you can just use

#information h2
#information h4

#information will always be contained within the #header which will always be contained within the table of the #wrapper, making everything before #information redundant.

Melissa Brookstone wrote:

Inefficient rules (good to fix on interactive pages):

#wrapper #footer p a Tag key with 3 descendant selectors
#navcontainer ul li Tag key with 2 descendant selectors


Here it's saying you can just use "#footer p a" or maybe just "#footer a" and just "#navcontainer li" because the "ul" is redundant.

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.