3 ms·
I was under the impression that jQuery cached selectors, so the advice "Cache jQuery Objects", while smart for many reasons, would not actually affect performan
by alexh 15y ago
I was under the impression that jQuery cached selectors, so the advice "Cache jQuery Objects", while smart for many reasons, would not actually affect performance much at all.
Was I wrong?
- dmethvin 15y agoIt depends on the selector and the browser. Something like $(".myclass") is worth caching on IE7 because it requires a pass through the entire document; there's no `querySelectorAll` or `getElementsByClassName`. I wouldn't start by caching selectors all over the place unless you profile and see that it's slow. Doing a lot of selecting in a `scroll` or `mousemove` handler would be a bad idea though: http://ejohn.org/blog/learning-from-twitter/ http://ejohn.org/blog/learning-from-twitter/