I just started working with jQuery and I have been searching for some type of resource on how to improve the speed/performance of my code. I was wondering if anyone had any tips or resources that could possibly help me out.
Thanks,
Bev
jQuery is in constant development and improvement. John and his team are always researching new ways to improve program performances. As a sidenote, just a few months ago, he released Sizzle, a selector library that's said to improve program performances up to 3 times in Firefox.
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.
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.
I had a few sites bookmarked on this very topic, hopefully they will help you out with what you need. (Topics range from simple to advanced)
jQuery Performance Rules topics include :
- Always Descend From an #id
- Use Tags Before Classes
- Cache jQuery Objects
- Harness the Power of Chaining
- Use Sub-queries
- Limit Direct DOM Manipulation
- Leverage Event Delegation (a.k.a. Bubbling)
- Eliminate Query Waste
- Defer to $(window).load
- Compress Your JS
- Learn the Library
jQuery Performance and Optimization Tips topics include :
- Stay up to date! Are you using methods and techniques that are obsolete?.
- Context-aware jQuery Code Execution – Are you loading code that isn’t needed?
- jQuery Unit Testing
- Benchmark Your jQuery Code
- Keep download times to a minimum with one compressed master JS file.
- Context Vs. Find
- Window.load all the way.
- Strike A Balance Between Your Use Of JavaScript & jQuery
jQuery Performance Tuning Tips - Paul Irish topics include :
- Optimize selectors for Sizzle’s ‘right to left’ model
- Use live() not click()
- Pull elements off of the DOM while you play with them
- Use find() rather than context
- Use HTML 5
- Append style tags when styling 15 or more elements
- Test selectors using Google Page Speed
- Use object detection even if jQuery doesn't throw an error
- Use direct functions rather than their convenience counterparts
- Learn the lesser known methods
Improving jQuery Performance with Large Data Sets topics include :
- Use JavaScript native for() loop instead of jQuery's $.each() helper
function.- Do NOT append an element to the DOM in your loop.
- If you have a lot of elements to be inserted into the DOM, surround them
with a parent element for better performance.- Don't use string concatenation, instead use array's join() method for a very long strings.
- Use setTimeout() function for your long list looping and concatenation
functions.
Hopefully these will be enough to get you started on your journey to jQuery performance heaven.
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