Skip to content

Instantly share code, notes, and snippets.

@KaySchneider
Last active June 10, 2017 07:23
Show Gist options
  • Save KaySchneider/ecdb98d24e6db6c3ca18879aac31cf2f to your computer and use it in GitHub Desktop.
Save KaySchneider/ecdb98d24e6db6c3ca18879aac31cf2f to your computer and use it in GitHub Desktop.
var cacheName = 'notenrechnerjk829829328931';
var filesToCache = [
'/notenRechner/',
'/notenRechner/manifest.json',
'/notenRechner/index.html',
'/notenRechner/libs/material.min.js',
'/notenRechner/libs/material.min.css',
'/notenRechner/js/app.js',
'/notenRechner/styles/main.css',
];
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open(cacheName).then(function(cache) {
console.log('[ServiceWorker] Caching app shell');
return cache.addAll(filesToCache);
})
);
});
self.addEventListener('fetch', function(e) {
e.respondWith(
caches.match(e.request).then(function(response) {
return response || fetch(e.request);
})
);
});
self.addEventListener('activate', function(e) {
e.waitUntil(
caches.keys().then(function(keyList) {
return Promise.all(keyList.map(function(key) {
if (key !== cacheName) {
console.log('[ServiceWorker] Removing old cache', key);
return caches.delete(key);
}
}));
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment