Member-only story
Want To Build Faster Web Apps? Use JavaScript Memoization
A practical example for better HTTP performance

Memoization is simply caching the output of a function so that the consequent calls just use the cached result, eliminating any heavy computation. Memoization in JavaScript can also yield amazing performance benefits, given that it is implemented properly.
Do you want to make your JavaScript code run much faster? In this article, we will have a look at a practical example of JavaScript memoization.
Spoiler alert: You will not see a Fibonacci or factorial mentioned below.
What Is Memoization?
An oversimplified definition of memoization is that when you run an expensive function with parameters a and b, you will cache the result of that function. When the same expensive function is called with the same parameters a and b, as the output is known and in the cache, the cached result is sent back.
Wikipedia defines memoization as:
“In computing, memoization or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.”
It further adds:
“A memoized function ‘remembers’ the results corresponding to some set of specific inputs. Subsequent calls with remembered inputs return the remembered result rather than recalculating it, thus eliminating the primary cost of a call with given parameters from all but the first call made to the function with those parameters.”
Pro tip: Memoization is also useful for software scalability. We will learn about that later in this article.
Not Another Factorial or Fibonacci Example
To be honest, I am bored with the same Fibonacci and factorial examples to explain memoization. Both Wikipedia and eight out of the ten results for a Google search for “JavaScript memoization” use either factorial or Fibonacci as the example. Yes, we used to do it in university to understand recursion maybe. But in day-to-day real-life coding, I have not used something like a factorial or…