What are some quick tips for increasing jQuery performance?
For small websites and simple web apps, the advantages of jQuery will often outweigh the minimal performance impact. For larger websites and web apps with thousands of lines of code, or those processing large amounts of data using JavaScript then performance is absolutely something to consider.
Nearly all plain Javascript functions will be faster than jQuery operations. This is because jQuery has overhead in creating a jQuery object in order to be more flexible, allow for chaining, support collections, etc...
jQuery is a wrapper that normalizes DOM manipulation in a way that works consistently in every major browser. It's fully reasonable for it to perform 25x slower than direct DOM manipulation.
find
function to find elements within the scope of that elements children. This is really only optimal if you are performing some operations on the common ancestor anyway; otherwise the overhead of finding the ancestor and caching it may outweigh the benefit of scoped traversal.$.each()
, use for(;;)
instead. It's over ten times faster.Paul Irish recently did a presentation on performance at the jQuery Conference 2009. The slides are some of the most comprehensive that I have seen.
http://paulirish.com/perf/
http://www.slideshare.net/paul.irish/perfcompression
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With