1.避免包含 jQuery extensionsjavascript
jQuery extensions會只用本地的querySelectorAll()java
// Slower (the zero-based :even selector is a jQuery extension) $( "#my-table tr:even" ); // Better, though not exactly equivalent $( "#my-table tr:nth-child(odd)" );
2.避免過分特性jquery
$( ".data table.attendees td.gonzalez" ); // Better: Drop the middle if possible. $( ".data td.gonzalez" );
3.儘可能使用id選擇器api
// Fast: $( "#container div.robotarm" ); // Super-fast: $( "#container" ).find( "div.robotarm" );
4.避免通配符選擇ui
$( ".buttons > *" ); // Extremely expensive. $( ".buttons" ).children(); // Much better. $( ":radio" ); // Implied universal selection. $( "*:radio" ); // Same thing, explicit now. $( "input:radio" ); // Much better.