Performance Optimization in JavaScript: Chapter Overview
Performance Optimization = how to stop a function doing more work than it needs to.
This chapter has 1 lesson and 4 exercises you run and check in your browser. Plan on about 25 minutes.
- Performance Optimization: debounce, throttle and memoisation.
After this chapter, you can:
- Run a search only after the user stops typing (debounce).
- Update the page at a steady rate while scrolling (throttle).
- Remember slow results so they are not worked out again (memoisation).
- Choose the right tool for each situation.
Every lesson has short explanations, code boxes you edit and run in the live editor, and a web page example you can click.
Before you start, finish Modules and Clean Coding.
Next chapter: Reference.
Lessons in this section
- Performance Optimization
Debounce for search boxes, API calls and form input; throttle for scroll, mouse-move and click events; memoization for caching the results of slow, repeated calculations; and how to choose between them.
- Write a debounce function and use it for search, API calls and user input
- Write a throttle function and use it for scroll, mouse-move and click events
- Write a memoize function that caches results in a Map
- Build a cache key that covers every argument