-
Notifications
You must be signed in to change notification settings - Fork 3
/
service-worker.js
42 lines (35 loc) · 1.22 KB
/
service-worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
* See https://goo.gl/2aRDsh
*/
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});
const queue = new workbox.backgroundSync.Queue('syncQueue');
self.addEventListener('fetch', (event) => {
console.log("Fetching: " + event.request.url);
// Clone the request to ensure it's save to read when
// adding to the Queue.
const promiseChain = fetch(event.request.clone())
.catch((err) => {
return queue.pushRequest({request: event.request});
});
event.waitUntil(promiseChain);
});
/**
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
workbox.precaching.precacheAndRoute([]);