Chapter 10
Writing Effective jQuery Code
WHAT’S IN THIS CHAPTER?
- JavaScript Optimization Techniques
- Using JavaScript Patterns
- The $.data() Method
Now that you’ve walked through the breadth of what jQuery has to offer, it’s time to look at some specific ways in which you can improve your jQuery code.
In this chapter, you learn a variety of techniques, best practices, and patterns that you can apply to your code immediately to make it more efficient, maintainable, and clear.
You’ll discover optimization techniques pulled from an understanding of JavaScript fundamentals, an understanding of the relationship between the DOM and the JavaScript engine in web browsers, and from the way CSS selectors are parsed by Sizzle and other selector engines.
You also learn about common jQuery patterns and how best to use them to create maintainable, clear code for use in projects of all shapes and sizes.
Finally, you are introduced to the jQuery $.data() method, which enables you to store and retrieve application data in a clear, standardized way.
After reading this chapter, your code will be faster and your coworkers will applaud you for your code organization.
OPTIMIZATION TECHNIQUES
This section focuses on a variety of simple optimization techniques to keep in mind when writing jQuery, or, in many cases, pure JavaScript code.
Be warned — once you start to pay strict attention to performance, it can infect all of your coding.
Your users will love you.
Minimize DOM Updates
One of the most fundamental ...