Have CSS selectors highlighted greater performance?

I have a web application with a bunch of HTML code. There are some style attributes that I cannot get rid of, but I was wondering if it would be worth the cleanup to get rid of the class names and use the CSS selector instead. CSS selectors run slow?

I'm talking about replacing class selectors like .example with more complex selectors like #example div> div: nth-child (3)> p

+3
source share
4 answers

Check out this article to see a graph of this. I don't know how accurate this breakpoint is, but it seems that child selectors are really slower, but you won't find any visible winnings by avoiding descendant selectors. This is a micro-optimization that has a “diminishing return” written by everyone above it.

+4
source

Achieving performance is negligible.

+1
source

, . *

1 – :

.foo p

2 –

.foo p.bar

, , , foo.

, bar, , , , foo.

, , .

* Keep in mind that a hit will really only show up when poorly crafted CSS is on very large (megabytes) pages and / or has many, many elements (like hundreds spanor divs). Small pages with few elements will not display in real time if any of the performance gains even with poorly written CSS.

0
source

Source: https://habr.com/ru/post/1738802/


All Articles