web2019/static/sw.js

35 lines
845 B
JavaScript
Raw Normal View History

var CACHE_NAME = 'ml-03';
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);
}
});