I need to store about 3-4mb of data (USPS address data mapping zip code to county across the entire US) in the frontend code for fast retrieval. The primary use case is that my users will type in their zip code and I need to tell them what counties they are in.
Storing the data in a plain JSON file in the frontend repo seems like a bad idea because it blows up my app size.
I don't want to retrieve it via an API because the input field performs logic that requires the address data on 500-1000ms delayed keystroke.
My main approach now is to load all the data via API when the app is loaded, and store it into IndexedDB if it doesn't exist already. The annoying part here is it's not obviously "instant" to call an API that returns 3mb of data. An optimization here is that I could just return the data for the county or state that I think the user might be in based on getCurrentPosition() first (unless not allowed), with a follow up async call to return the rest.
Are there any other strategies that I might be missing?