Caching resource data
Our first approach to providing a better experience when an internet connection is slow or unreliable is to implement a caching mechanism for our remote resources. With this in place, a single online run of the application would be sufficient to defend against connectivity problems as it'll populate the cache data. The bonus is that, on repeated runs of the application, it'll be much faster to load these resources.
Building on the previous image example, we implement a new function, cacheStream(), which we'll call instead of readStream(). A helper function called cacheFileName() establishes a file location to use for the cache based on a url parameter. Every time we request a URL using this function, it'll attempt to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access