Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The universal selector has the potential to be slower than other selectors in naïve CSS engines because CSS works by matching selectors from the right to the left. A rule like `.baz *` matches every element on the page (vs something like `.baz .foo` which only matches elements with `.foo`). The match is only rejected after walking up the DOM tree to the root node to see if any parent elements have the `.baz` class or not.

In the case of a single universal selector, there is no performance issue, the selector just matches every element, which is fine.

In modern engines, there is also no performance issue, they JIT compile selectors[0] and do other stuff to be fast. Even old engines wouldn’t really have a performance issue in practice unless you were doing something else bad, like having extremely deep DOM trees with extremely large numbers of elements.

[0] https://webkit.org/blog/3271/webkit-css-selector-jit-compile...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: