From the course: JavaScript: Service Workers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Deliver alternate content when offline - JavaScript Tutorial
From the course: JavaScript: Service Workers
Deliver alternate content when offline
- [Instructor] I'm back in my project in 04_09, and we need to remember that, besides loading font, CSS, images, and JavaScript files, we also have in the weather.js file in our project, a call to an API. That API is in explorecalifornia.org, so its in a different host. It's not in our host, that's local host. But any way the service worker can see an answer for that request because it's our website in our scope the one that is making that request. In this case, I don't want to use any of the previous policies for caching the weather because, of course, weather data is changing frequently. I don't want to cache that. So I want to use a different strategy here. If you look in the root folder, I do have an offline.json file. That offline.json file is the one that I'm going to deliver when there is no connection. So weather need the weather JS file to read that error message and if that error message exists with a true then we are not going to try to get the temperature information…
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
-
-
-
-