Service Workers are the most significant addition to the web platform since the introduction of AJAX. This course will show you why, and help you leverage the power of Service Workers to make your web apps work without an internet connection.
Leveraging the Cache API In the last module we successfully registered, installed, and activated a Service Worker, and we were able to serve a very simple offline experience, but the one thing that was really lacking from that first Service Worker of our was the ability to store files and content into some safe place that the user can access even while they're offline. Well that's where the Cache API comes in, and it's what we're going to be spending the rest of this module looking at. The Cache API is defined as a part of the Service Worker specification itself. Now that can be a little confusing, but it's important to note that the Cache API is not specific to Service Workers. In fact, they can be used on both the worker object inside of a Service Worker or on the window object inside of the normal scripting environment that you are probably used to already, and like Fetch, it's also defined as a living standard, which means it's going to be updated and changed over time, so expect things to get better as we go. The Cache API is available in all the places you'd expect it to be. Because it's part of the Service Worker specification, its support looks very similar to the browser support for Service Worker itself. You'll find it in Chrome since version 46, Firefox since 44, and Opera since 33. It's currently in development in Edge, and not available in IE or Safari. Let's dive into the Cache API and see how it works.
Common Patterns & Practices With the fundamentals of caching under our belts I wanted to take some time to cover common patterns and practices that you can use to make creating Service Workers much easier. The first set of things that we'll look into is some common caching patterns. I'm going to highlight five key patterns, and I'll tell you how they work, and when you might want to use them, but there are certainly a lot of other caching patterns available as well. In fact, both Mozilla on the MDN network, and Google on their own developer network have caching pattern catalogs called the Service Worker Cookbook, and the Offline Cookbook respectively. I've included links to both of those cookbooks in the course notes that you'll get at the end of this module, so let's dive in.