From the course: JavaScript: Service Workers
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Implement a cache-first policy - JavaScript Tutorial
From the course: JavaScript: Service Workers
Implement a cache-first policy
- [Instructor] Back in our California project we have already saved all the files in the cache, but no one is serving those files. So we actually need to listen for the fetch event handler, the same that we did before. And we're going to do this, we are going to respond with, and we need to respond with a promise of a response or an actual response. So we need to go to the cache and see if it's there. So to go to the cache we need to use caches.match. Caches.match will look for a request in that cache, and it will return a promise with the found object if it was found. For example in this case we want to search for the request that the browser is actually asking for. So event.request, and we're going to match that request. In this case we are not saying in which cache we want to search, so this API will look into all the caches available in our origin. So if we want to specify exactly the cache, we can also do that first. Opening the cache and then executing match inside the cache…
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
-
-
-
-
-
-
Understand the new Cache API5m 36s
-
(Locked)
Prepare the project4m 30s
-
(Locked)
Prefetch files on install5m 1s
-
(Locked)
Visualize your cache3m 37s
-
(Locked)
Implement a cache-first policy6m 12s
-
(Locked)
Implement a network-first policy5m 10s
-
(Locked)
Cache new elements after install5m 41s
-
(Locked)
Use stale-while-revalidate6m 46s
-
(Locked)
Deliver alternate content when offline6m 28s
-
(Locked)
Keep your storage clean5m 28s
-
(Locked)
Summary of cache strategies4m 36s
-
-
-
-