-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
38 lines (30 loc) · 882 Bytes
/
sw.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
// Polyfill for Chrome caching
//importScripts('scripts/cache-polyfill.js');
'use strict';
// Install the ServiceWorker
self.addEventListener('install', function(event) {
event.waitUntil(
// Open a cache
caches.open('v1').then(function(cache) {
// Define what we want to cache
return cache.addAll([
'/offline.html',
]);
})
);
});
//service worker actived
self.addEventListener('activate',evt => {
console.log("service worker actived");
})
// Use ServiceWorker (or not) to fetch data
self.addEventListener('fetch', function(event) {
event.respondWith(
// Look for something in the cache that matches the request
caches.match(event.request).then(function(response) {
// If we find something, return it
// Otherwise, use the network instead
return response || fetch(event.request);
})
);
});