How would I go about testing the performance benchmarks of different css selectors? I've read articles like this. But I don't know if it is applicable to my website because he used a test page with 20000 classes and 60000 DOM elements.
Should I even care,does performance really get downgraded that much based upon the css strategy you take?
Fo example, I like doing this ...
.navbar { background:gray; } .navbar > li { display:inline;background:#ffffff; } <ul class="navbar"> <li>Menu 1</li> <li>Menu 2</li> <li>Menu 3</li> </ul>
... but I could do this ...
.navbar { background:gray; } .navbar-item { display:inline;background:#ffffff; } <ul class="navbar"> <li class="navbar-item">Menu 1</li> <li class="navbar-item">Menu 2</li> <li class="navbar-item">Menu 3</li> </ul>
Some would say (and might be right) that the second option would be faster.
But if you multiply the second method across all pages I see the following disadvantages:
My pages seem to be ~ 8KB with ~1000 DOM elements.
So my real question is how do I create a test bed where I could test performance deltas based on strategy taken for realistic web page sizes? Specifically how do i know how long it takes for a page to be displayed? javascript? how exactly?
Help and just plain opinions are welcome!
popupbutton is the fastest.
Call querySelector() or querySelectorAll() depending on what you want to test, and check the return value (preferably in your browser's developer tools since you're just testing): If matches are found, the former method returns the first Element matched while the latter returns all elements matched as a NodeList .
Check out the Page Speed extension for Firefox. Once you run it for a page, under "Use efficient CSS selectors" it gives you a list of the offending CSS selectors along with brief explanations.
Also, there's another extension for Chrome - Speed Tracer. Amongst other things, it offers insight into time spent on CSS style recalculation and selector matching. This may just be what you are looking for.
From reading the article you listed it looks like the difference between the two type of selectors is not worth worrying about. Make certain the css is clear enough to understand it, and only worry about speed after that proves to be the bottleneck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With