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

Deliver alternate content when offline - JavaScript Tutorial

From the course: JavaScript: Service Workers

Start my 1-month free trial

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…

Contents