const CACHE_NAME = 'ktvmanager-cache-v1'; const urlsToCache = [ '/', '/static/styles.css', '/static/favicon.ico', '/static/favicon-96x96.png', '/static/favicon.svg', '/static/apple-touch-icon.png', '/static/web-app-manifest-192x192.png', '/static/web-app-manifest-512x512.png', '/static/site.webmanifest' ]; self.addEventListener('install', function(event) { event.waitUntil( caches.open(CACHE_NAME) .then(function(cache) { console.log('Opened cache'); return cache.addAll(urlsToCache); }) ); }); self.addEventListener('push', function(event) { const data = event.data.json(); const options = { body: data.body, icon: '/static/web-app-manifest-192x192.png', badge: '/static/favicon-96x96.png' }; event.waitUntil( self.registration.showNotification(data.title, options) ); }); self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request) .then(function(response) { if (response) { return response; } return fetch(event.request); } ) ); });