However, it made many assumptions about what you were trying to do and then broke horribly when your app didn’t follow those assumptions exactly.
Read Jake Archibald's (unfortunately-titled but well-written) Application Cache is a Douchebag for more details.
In the resolved case, we display the image inside To demonstrate just the very basics of registering and installing a service worker, we have created a simple demo called sw-test, which is a simple Star wars Lego image gallery.
It uses a promise-powered function to read image data from a JSON object and load the images using Ajax, before displaying the images in a line down the page. It also registers, installs, and activates a service worker, and when more of the spec is supported by browsers it will cache all the files required so it will work offline!
After your service worker is registered, the browser will attempt to install then activate the service worker for your page/site.Using a Service worker you can easily set an app up to use cached assets first, thus providing a default experience even when offline, before then getting more data from the network (commonly known as Offline First).This is already available with native apps, which is one of the main reasons native apps are often chosen over web apps.Those features are not used here so that you can focus on understanding Promises.method, which contains two functions — the first one is executed when the promise successfully resolves, and the second is called when the promise is rejected.