2018-09-20 01:59:07 +02:00
|
|
|
const CACHE_NAME = 'awmw-cache';
|
|
|
|
const PRE_CACHED_ASSETS = [
|
|
|
|
'/assets/css/materialize.min.css',
|
2018-09-20 02:28:21 +02:00
|
|
|
'/assets/css/style.css',
|
2018-09-20 01:59:07 +02:00
|
|
|
'/assets/css/syntax1.css',
|
|
|
|
'/assets/js/materialize.min.js',
|
|
|
|
'/assets/js/particles.min.js',
|
|
|
|
'/assets/js/init.js',
|
|
|
|
'/index.html'
|
|
|
|
];
|
|
|
|
|
|
|
|
self.addEventListener('install', function(event) {
|
|
|
|
event.waitUntil(
|
|
|
|
caches.open(CACHE_NAME).then(function(cache) {
|
|
|
|
let cachePromises = PRE_CACHED_ASSETS.map(function(asset) {
|
|
|
|
var url = new URL(asset, location.href);
|
|
|
|
var request = new Request(url);
|
|
|
|
return fetch(request).then(function(response) {
|
|
|
|
return cache.put(asset, response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return Promise.all(cachePromises);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
self.addEventListener('activate', function(event) {
|
|
|
|
event.waitUntil(
|
|
|
|
caches.keys().then(function(cacheNames) {
|
|
|
|
return Promise.all(
|
|
|
|
// delete old caches
|
|
|
|
cacheNames.map(function(cacheName) {
|
|
|
|
if (cacheName !== CACHE_NAME) {
|
|
|
|
return caches.delete(cacheName);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
self.addEventListener('fetch', function(event) {
|
|
|
|
if (event.request.headers.get('accept').startsWith('text/html')) {
|
|
|
|
event.respondWith(
|
|
|
|
fetch(event.request).catch(error => {
|
|
|
|
return caches.match('index.html');
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|