-
Notifications
You must be signed in to change notification settings - Fork 19
CSS coding standard: outdated links #69
Comments
Current situationCurrently, the section on efficient CSS selectors is as below:
After some amount of experimentation and research, I think the Mozilla Developer Network warning (as mentioned in the opening post) has merit. The section in the guidelines on writing efficient CSS selectors seems irrelevant and possibly outdated. Let's look at whether these two points have merit: Do not qualify class/ID selectors using tag namesUsing the following tests, we can see that the differences in page load times and reflow times is pretty much non-existent, even when dealing with a page with 1000 elements affected by 1000 CSS selectors. Unqualified class selectors Use child selector rather than descendant selectorThe same non-existent difference can be observed with child vs descendant selectors here: Child selector ConclusionI think most resources (books, websites, etc.) when talking about writing efficient CSS based their advice on the article written by David Hyatt back in 2000. A lot has changed with CSS and browsers since then, and his original points don't seem too relevant now. I would argue that even if they do make a difference, it is so insignificant that it's not worth the time and effort (a few ms difference, even with 1000 CSS selectors on 1000 elements). It is not a bottleneck in page load times, as evident from the above examples. I think it would be better to focus on readability, maintainability, and flexibility rather than these micro-optimizations, and that this section should be removed. Thoughts? @damithc @kychua @yamgent @chao1995 @MightyCupcakes |
Copying @acjh |
There are 2 main considerations:
I would agree that the difference in performance is no longer very significant. It may be noteworthy that Google still has that guideline, citing a 2009 article on performance. I believe that performance simply serves as an easy way to justify optimizations. In this case, it's not sufficient if it were the sole rationale.
First, readability.
Second, maintainability.
Third, flexibility.
Fourth, specificity.
|
As mentioned in the 2009 article, it is based off a chapter from the book, "Even Faster Web Sites: Performance Best Practices for Web Developers", also published in 2009. I have checked the book out, and in it the author states that he too based his points off the guidelines outlined in the original article from 2000. I agree with the excellent points brought up about readability, maintainability, flexibility, and specificity. The strongest argument to be made here is an update to the guideline for CSS selectors rather than an outright removal. Rather than focusing on efficiency of CSS selectors, I think it would be more meaningful to base guidelines on the four points mentioned above. For instance, rather than stating
Ultimately, my point would be that it would be better to base the guidelines on other factors than efficiency. The existing guidelines on CSS selectors do not represent a significant bottleneck in page load times, and thus shouldn't be a priority. Of course, it would be good to include a section on writing efficient CSS should there be any good points, but I think it should be backed by actual data, and right now it doesn't seem to be. |
Agree with @acjh's recommendation. @PierceAndy If efficient CSS is irrelevant today, then that section shouldn't exist at all. Not an expert of browser-based CSS though, so you might want to consult the TEAMMATES people about that. :P |
Over at teammates, we're not using a lot of custom css thanks to bootstrap. Regarding performance, that should not be an issue, cutting down the size of the css file will do much more than optimizing selectors. @acjh's points on maintainability and flexibility are still very valid. Personally I feel that good css should not have too many layers or nesting, thus I prescribe to BEM among other css architectures to keep css maintable. |
CodingStandard-Css.md
is outdated.has moved to
A web archive presents us with the following warning:
The text was updated successfully, but these errors were encountered: