Another test (https://benfrain.com/selector-test/2-01.html): I grabbed a big fat style sheet that had absolutely no relevance to the DOM tree. It was about 3000 lines of CSS. All these irrelevant styles were inserted before a final rule that would select our inner a.link
node and make it red. I did the same averaging of the results across 5 runs on each browser.
Half those rules were then cut out and the test repeated (https://benfrain.com/selector-test/2-02.html) to give a comparison. Here are the results:
Test |
Chrome 34 |
Firefox 29 |
Opera 19 |
IE 19 |
Android 4 |
Full bloat |
64.4 |
237.6 |
74.2 |
436.8 |
1714.6 |
Half bloat |
51.6 |
142.8 |
65.4 |
358.6 |
1412.4 |
This provides some interesting figures. For example, Firefox was 1.7X slower to complete this test than it was with its slowest selector test (test 6). Android 4.3 was 1.2X slower than its slowest selector test (test 6). Internet Explorer was a whopping 2.5X slower than its slowest selector!
You can see that things dropped down considerably for Firefox when half of the styles were removed (approx 1500 lines). The Android device came down to around the speed of its slowest selector at that point too.
Does this kind of horror scenario sound familiar to you? Enormous CSS files with all manner of selectors (often with selectors in that don't even work), heaps of ever more specific selectors seven or more levels deep, non-applicable vendor-prefix's, ID selectors all over the place and file sizes of 50–80 KB (sometimes more).
If you are working on a code base that has a big fat CSS file like this, one that no-one is quite sure what all the styles are actually for, my advice would be to look there for your CSS optimisations before the selectors being employed. Hopefully by this point you will be convinced that an ECSS approach might help in this respect.
Then again, that won't necessarily help with the actual performance of your CSS.
3.133.152.198