You can get data for the Typeahead via Ajax in two ways:
Fetch all data before activating the Typeahead
Fetch data as user types into the input field
When to use Method 1
You want to use method 1 if you have a small amount of data to fetch. If you have less data, users need to wait a lesser amount of time before they use the Typeahead.
Also, you won’t have to worry about debouncing, optimising performance, and all the complicated ajax stuff.
When to choose Method 2
You only want to use Method 2 if:
You have a large amount of data (too much to download).
You cannot predict what users will type.
A good example here is Google. You can’t predict what users would search for. Trying to download the entire search index is going to be way too expensive for users.
Other good examples include search results.
What we’ll use
Since the Typeahead requires a small amount of data, we’ll use the first method.