1
0
Fork 0
web2019/static/sw.js

40 lines
1005 B
JavaScript

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',
'/js/react.production.min.js',
'/js/react-dom.production.min.js',
'/js/prop-types.min.js',
'/js/react-beautiful-dnd.min.js',
'/js/uuid_v4@latest.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);
}
});