Forum Moderators: not2easy
Complex applications like Yahoo! Mail benefit from simplified selectors and improved rendering times because of the amount of work that is being done on the client. If you have a blog then it really isn't an issue because the page is rendered once, with few rules needing to get evaluated. Changing everything to ID or class selectors won't be worth the maintenance headache.
ul.one li p a - you have qualified the ".one" class by adding the "ul" element to it. This always irked me that it, "qualifying", appeared in warning messages, as it's possible to use a class name on multiple elements (tags) and you may very well need to qualify the class in order to get specific. Theoretically modules or plugins can introduce identical class names too so it's not just a simple case of ensuring your own CSS only attaches a class name to a particular element, e.g. class="list" can only be used on <li> elements, which is most people understanding of the warnings given. ul.one li p a efficient.it becomes (for my code - do not take this as gospel without reading further!) ul.one>li>p>a
li p a {} it might have to look back the whole document tree, all the way back to the root body tag at times.. to see if there's any chance there's a <p> in an <a>'s ascendancy, before it can then start the lookback all over again to see if all <p>'s matched have an <li> in their ascendancy.. in other words multiple lookbacks may have to occur
- ul>li a {}
- ul>li>a {}
ul>li>p>a, ul>li>strong>a {} - btw I removed the <p> and <strong> elements, which would have meant that rule #2 would possibly have been my best choice for efficiency, then rechecked just in case PageSpeed had got really clever matching subtly unused to efficiency.. but no.. it still didn't flag ul>li a {} as inefficient, cool I would have hoped not that would really make "efficient" maintenance an impossibility ;) ul.one>li a - not an unreasonable request given that one way around most of the warnings is to add classes to everything - I got a warning again though this time it was not "Very Inefficient (good to fix on all pages):" like the previous ones had been.. just inefficient "Inefficient rules (good to fix on interactive pages):" and there's the clue.. interactive pages, most are these days what with JS libraries being built into most CMS'es and other fancy plugins abounding ul.one>li>p>a, ul.one>li>strong>a {} is one way, and changing the class to an ID so making it unique and removing the need to qualify the tag too, does it too #one>li a {} or simply ensuring that you never have clashing class names (fairly impossible) so removing the need to qualify too.. ... the fewer rules the engine has to evaluate the better. So, of course, removing unused CSS is an important step ... After that, for pages that contain large numbers of elements and/or large numbers of CSS rules, optimizing the definitions of the rules themselves ... The key to optimizing rules lies in defining rules that are as specific as possible and that avoid unnecessary redundancy, to allow the style engine to quickly find matches without spending time evaluating rules that don't apply.Which makes clear that pagespeed's approach to optimiosation is premised on large numbers of elements and css rules, salted with lots of unused css. Firmly in the yui grids family.
I'm not against writing code that uses the most efficient selectors. I just doubt claims that making selectors more specific will make code more efficient when the real inefficiency problem is html and the bloated css used to style it,
I don't have to support IE6 any more;) ... and some sensitivity for the less fortunate would be appreciated ...sniff ... ;)
You are right though, unless you've already optimised everything else, HTML, Images, reduced http requests, parallelized downloads etc.. then "fine tuning" the CSS likely won't register.. but if you are really tight or are chasing that green tick, like some seem focused on, then I figured it might be an interesting exercise, if nothing elseOf course an interesting exercise - your findings were fascinating, as usual. I'm especially impressed by your discovery that specificity is weighted more highly than redundancy is penalised.
The Page Speed extension is the fastest way to get accurate performance analysis of your web pages.I don't think pagespeed does that at all, and my concern is that unless that is fully understood, we risk developing a belief system that really confuses efficiency with pages getting a green tick, even though the tick is meaningless outside the scope of the purpose-specific definition of efficiency, and in some cases the techniques used to acquire it are really quite harmful.
With Page Speed, you can make your site faster, keep Internet users engaged with your site, reduce your bandwidth and hosting costs and improve the web!But to the point, I've always suspected the "scores" were weighted". Your finding regards the redundancy/specificity relationship seems to reinforce that. Did your testing produce anything interesting in terms of weightings between different factors - like compression over server hits, etc?
I'm sure common scores are 83 or 88, as as if there is a benchmark/weighting scheme that makes that reasonably/generally achievable. Any thoughts?
YSlow - 85
Pagespeed - 72
Load speed - 1.217
http requests: 34
---
PS score for unused CSS - (72.8) C
PS score for Efficient CSS - (0) F
YSlow - 91
Pagespeed - 84
Load Speed - 1.06
http requests - 14
---
PS score for unused CSS - (59.2) E
PS score for Efficient CSS - (0) F
fickering [scottish word for messing]he he. Is this the modern form of fichering? Recalling our Scots stopped evolving ... or maybe treated as the Germanic root if that is still in use.
weighted - definitely yes - some sites might take care of one part some of another, making it balance itself out?But if that's the case the whole scoring system is as sensible as putting a sea anchor on a formulae one race car.
[how can the unused code differ if I haven't changed it? hmm]I know that's rhetorical - but possibilities:
and make the selectors as efficient as possible at the same timeOh what fun:) Looking forward to the results - but is that "pagespeed efficient" - which seems to mean specific?
if you were just to optimise a module image to the same location it comes from it would overwrite the next time that module updated - so I think I'm about to learn another lessonAnd this would be ... responsible citizenship means official repositories should only publish modules that meet minimum standards of optimisation? :)
out of interest, have you run your test pages through web page analyser [websiteoptimization.com] to get a "feel" for how they perform according to more generally understood definitions of "performance" and "efficiency"?
And this would be .
So do your tests show if there is a score differential between
# just id's versus just classes,
# just classes versus multiple classes
# specific descendent selectors versus just id's versus just classes
table#mytable td {} - because not only do you get the "over qualified by an element" warning but a td is one of two possible descendant trees for a table and even if you remove the qualifier (reduce specificity) you get the same warning.. the tree from that could be #mytable>thead>tr>td or it could be #mytable>tbody>tr>td tr class="even bold" and no I don't advocate naming a class after an effect but I can only describe so much in type! [edited by: alt131 at 3:21 am (utc) on Oct 17, 2011]
[edit reason] Thread Tidy [/edit]
Yes I've run them through every optimsation known to manI was looking for an independent measurement. To illustrate using an extreme example, if the code failed to get a single "congratulation", but pagespeed scored 100, then I have a feel for the code, plus a "gross error check" on the pagespeed scoring system.
a selector with only one descendant will be deemed "inefficient" no matter whether its parent is an ID or a class.. which surprises me, an ID with one descendant should be absolutely fine.. even two or three for goodness sakeThat's the effect that needs to be removed from the results. Recalling this is not about how selectors should work, organising css, or best code practises: Purely limited to identifying the easiest/ fastest way to obtain the "pagespeed efficiency" tick.
no differential between ID's and classes, though the more descendant classes you have, the bigger a "parent" chain you need to make it VERY efficient (unique)..That's the exact testing environment to avoid. Without knowledge of the internal weighting scheme combining selector types contaminates the results – the selectors need to be isolated. To illustrate, that td becomes:
... a selector with only one descendant will be deemed "inefficient" no matter whether its parent is an ID or a class...
... think tables.. to make a table selector efficient, you can't say table#mytable td {} - because not only do you get the "over qualified by an element"
it's gone down because now instead of asking me to optimise it's asking me to sprite and giving me a lower "score".Recalling the previously reported counting issue, to me this indicates either:
you will be writing a style per selector ... CSS will have been spoiled.. may as well call it SS … and … you will need to repeat yourself in the stylesheet.Yup, a style per selector, a selector per element - pagespeed seemed heading in this direction from the outset. Big on computing power, low on learning code. Hence my tests - to see how much the dark-side is already being rewarded. Frankly, I’d expected more tests and more outcry by now because so much indicates the proclaimed best seo advantage is achieved by discarding many of the basic premises of html and css.
for now, one of the top CSS "wants" is that we should be able to nest selectors to save repeating ourselves and maintain readability.. try it, get something like LESS or SASS, both of which work as intended, but is the way CSS is supposed to work?Nope ;) and best I can tell pagespeed doesn't want that either. But I think this highlights the mismatch – coders debate nesting selectors while the seo world is influenced by a tool that doesn't want more from html than divs. Small wonder many think css isn’t viable in the real world.
and lastly it's quite weird to peer inside a provided module and see some of your own code staring back at youOoooooooo K. Leaving aside the intellectual theft issue, ... you've got your code (which is usually clean and beautiful to read) with a big overhead, liberally salted with someone else's messes? You know I dislike libraries - are you trying to give me more reasons not to budge? ;)
Use class selectors instead of descendant selectors.
For example, if you need two different styles for an ordered list item and an ordered list item, instead of using two rules:
ul li {color: blue;}
ol li {color: red;}
You could encode the styles into two class names and use those in your rules; e.g:
.unordered-list-item {color: blue;}
.ordered-list-item {color: red;}
I guess that would be tr>td, although that's dumb, even for the dark side
.warning {} - if you do it will ultimately affect the entire table layout which you don't want.. how do you decipher between div.warning {} and td.warning {} without the "inefficient" qualifier?
tr > .warning {} - of course thead > tr > .warning {} over tbody > tr > .warning {} to differentiate the main td's over the header ones.. that is if the header ones aren't th's , they aren't always.. that's why I say that tables are exactly the logic to illustrate this point with (darn tables are always going to haunt us ;))
For example, if you need two different styles for an ordered list item and an ordered list item, instead of using two rules:
ul li {color: blue;}
ol li {color: red;}
You could encode the styles into two class names and use those in your rules; e.g:
.unordered-list-item {color: blue;}
.ordered-list-item {color: red;}
ol > li {color: red;}
ul > li {color: blue;} Somebody show me a real page that's not dynamically changing all the time (e.g. google's maps.google.com) where they can measure a difference in rendering speed based on a "ul li {...}" vs. a "ul>li {...}".
I claim it's unmeasurable.
html.no-js fieldset {} .no-js > body fieldset {} to make sure it goes back to the HTML element! ;)) YSlow - 85
Pagespeed - 72
Page Size: 241KB
Load speed: 1.217s
http requests: 34
---
PS score for unused CSS - (72.8) C
PS score for Efficient CSS - (0) F
YSlow - 86
Pagespeed - 86
Page Size: 168KB
Load speed - 1.39
http requests: 33
---
PS score for unused CSS - (79) C
PS score for Efficient CSS - (0) F
YSlow - 91
Pagespeed - 84
Page Size: 235KB
Load Speed - 1.06
http requests - 14
---
PS score for unused CSS - (59.2) E
PS score for Efficient CSS - (0) F
YSlow - 93
Pagespeed - 93
Page Size: 164KB
Load Speed - 1.12
http requests - 14
---
PS score for unused CSS - (56.1) E
PS score for Efficient CSS - (0) F
"Does pagespeed consider one "efficient" selector more "efficient" than others?
Although you have now moved to general optimisation techniques,
The chosen test page:
On a well-known site, mostly text, reasonably well-written code. I'm still struggling to find a pagespeed definition for "interactive", and this one may not qualify. But it provides an opportunity to test whether "non-interactive" pages respond the same way as "interactive" pages.
so just how do you minify JS?
java -jar yuicompressor-x.y.z.jar myfile.js -o myfile-min.js --charset utf-8
--charsetoption if your file is encoded in utf-8.
it appears it's only the google (analytics) code itself causing a problem I would presume you don't touch that