Chapter 8. Keeping JavaScript lean and fast

 

This chapter covers

  • Affecting the loading behavior of the <script> tag
  • Replacing jQuery with smaller and faster API-compatible alternatives
  • Using native JavaScript methods to replace jQuery functionality
  • Animating with the requestAnimationFrame method

The world of JavaScript has exploded into a mélange of libraries and frameworks, leaving us with a slew of options for developing websites. In our excitement to use learn and use them, we often forget that the surest path to a fast website is a willingness to embrace minimalism.

This isn’t to say these tools don’t have a place in the web development landscape. They can be quite useful and can save developers hours of writing code. The goal of this chapter, however, is to promote minimalism in your website’s JavaScript for the benefit of your users.

In this chapter, you’ll dive into what you can do to improve the performance of script loading on your website. You’ll also spend time learning about jQuery-compatible libraries that do much of what jQuery does, but with smaller file sizes and better performance. You’ll go one step further and investigate how to replace jQuery with in-browser APIs that deliver much of what jQuery provides, but without the overhead. Finally, you’ll learn to use the requestAnimationFrame method to code high-performance animations. Let’s get started!

8.1. Affecting script-loading behavior

8.2. Using leaner jQuery-compatible alternatives

8.3. Getting by without jQuery

8.4. Animating with requestAnimationFrame

8.5. Summary