From the course: Improving Performance with IndexedDB and Caching

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Retrieving files from the cache

Retrieving files from the cache - JavaScript Tutorial

From the course: Improving Performance with IndexedDB and Caching

Start my 1-month free trial

Retrieving files from the cache

- Now our images and CSS, have been stored in the cache. We can retrieve them in the next request. We're going to use a local first caching strategy here, as these files are unlikely to change very often. So we can safely store them in the cache, without having to worry about showing the user and outdated application. We will look at how to store different kinds of assets in the next video. First of all, we need to listen for the fetch event. We can do this by adding a new event listener for fetch, giving that a call back with the events property. This event fires when any http request is made. So we need to check that it is a request for one of the files we've cached. So I'm going to write an if statement and check that the request exists within the arrays of files that we have cached. To do that I'm going to create a new array, and I'm just going to spread the different kinds of files into that, right? Then I can…

Contents