jQuery Speed Tip of the Day
Lately I’ve become a huge fan of performance tweaks in my javascript. So this morning I decided to time some code I was writing. Quite frankly, it was just too slow.
This is what I started with…
$('#someDiv').find( 'dl.list:visible input[checkbox]' );
which I then converted into the following after a minute…
$('#someDiv').find( 'dl.list' )
.filter( ':visible' )
.find( 'input[checkbox]' );
I honestly was expecting a little, but not a ton. But!!! I got a performance gain from an average of 215ms to an average of 85ms. Over twice the speed on this selector from just adding a filter and another find.
