I’ve been living under a rock for a while it seems, as I’ve heard the term Service Worker before but had no idea what it is, does or how it works.
This guide does a stellar job of explaining it and showing a practical implementation of Service Workers.
Lots of JavaScript code examples along the way.
If you’re wondering what a service worker is, it’s like a little alien that lives on your page [in the browser] and relays messages for you. It can detect when you have an Internet connection and when you don’t, and can responds in different ways based on the response.
Source: Implementing “Save For Offline” with Service Workers