Does jQuery do any kind of caching of “selectors”?

后端 未结 14 2208
挽巷
挽巷 2020-11-27 18:14

For example, will the first piece of code perform a full search twice, or is it smart enough to cache results if no DOM changes have occurred?

if ($(\"#navba         


        
14条回答
  •  忘掉有多难
    2020-11-27 19:04

    jsPerf is down today, but this article suggests that the performance gains from caching jQuery selectors would be minimal.

    enter image description here

    This may simply be down to browser caching. The selector tested was only a single id. More tests should be done for more complicated selectors and different page structures...

提交回复
热议问题