Performance of jQuery selector with context

后端 未结 6 1421
南方客
南方客 2020-12-01 05:26

I was reading this article by Brandon Aaron here, about how jquery context may help. So i thought of doing a test of my own. So this is what I did.

  1. Created

6条回答
  •  渐次进展
    2020-12-01 06:25

    I've taken the JSBin code and put it into a jsPerf Test

    $context.find('.holder') is twice as fast as its closest competitor, $('.holder', $context) and that is a good ten times faster than any other selector being used.

    In conclusion, cache your selectors and use .find() for maximum performance

提交回复
热议问题