2019-07-31 16:02:40 +08:00
|
|
|
var CACHE_NAME = 'ml-03';
|
2019-07-29 18:23:36 +08:00
|
|
|
var urlsToCache = [
|
|
|
|
'/css/bootstrap-4.3.1.min.css',
|
|
|
|
'/css/styles.css',
|
|
|
|
'/js/jquery-3.3.1.slim.min.js',
|
|
|
|
'/js/bootstrap-4.3.1.min.js',
|
|
|
|
'/js/popper-1.14.7.min.js',
|
|
|
|
];
|
|
|
|
|
|
|
|
self.addEventListener('install', function(event) {
|
|
|
|
console.log('[SW] Install');
|
|
|
|
event.waitUntil(
|
|
|
|
caches.open(CACHE_NAME)
|
|
|
|
.then(function(cache) {
|
|
|
|
console.log('[SW] add to cache');
|
|
|
|
return cache.addAll(urlsToCache);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
self.addEventListener('fetch', function (event) {
|
|
|
|
console.log('[SW] Fetch');
|
|
|
|
event.respondWith(
|
|
|
|
caches.match(event.request).then(function (response) {
|
|
|
|
return response || fetch(event.request);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
self.addEventListener('message', function (event) {
|
|
|
|
if (event.data.action === 'skipWaiting') {
|
|
|
|
self.skipWaiting();
|
|
|
|
caches.delete(CACHE_NAME);
|
|
|
|
}
|
|
|
|
});
|