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 - JavaScript Tutorial
From the course: Improving Performance with IndexedDB and Caching
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
What is caching?1m 13s
-
Service workers1m 43s
-
Caching strategies1m 40s
-
Setting up your cache2m 57s
-
Caching static files2m 6s
-
Retrieving files from the cache3m 18s
-
Cache invalidation4m 37s
-
Challenge: Cache third-party files32s
-
Solution: Cache third-party files2m 44s
-
Profiling2m 22s
-
Caching data4m 52s
-
-
-