jQuery Performance

#1. Use ID, element selector

  • $('#news').show();
  • $('#login span').addClass('highlight');

#2. Avoid Pseudo as much as possible

#3. $(this).id is fastest way to retrieve id

http://jsperf.com/el-attr-id-vs-el-id/

#4. cache jQuery object

http://jsperf.com/ns-jq-cached

$('#menu').addClass('.highlight').prop('disable', false);

#6. $.delegate(), on() is faster than bind(), live()

http://jsperf.com/jquery-live-vs-jquery-delegate/

#7. use append() only once. But use html() is better if possible

http://jsperf.com/jquery-append-vs-html-20140422/4

#8. use detach when we want to re-insert a node

http://jsperf.com/to-detach-or-not-to-detach

#9. use for-loop instead of $.each

http://jsperf.com/jquery-each-vs-for-loop/

jQuery Performance

By Quy Tran

jQuery Performance

  • 2,806