diff --git a/web-app-vue/public/sw.js b/web-app-vue/public/sw.js index 4faf471..7dac371 100644 --- a/web-app-vue/public/sw.js +++ b/web-app-vue/public/sw.js @@ -1,39 +1,18 @@ -// https://docs.pwabuilder.com/#/home/sw-intro?id=example-worker +// This is the "Offline copy of pages" service worker -const CACHE_NAME = 'cool-cache'; +const CACHE = "pwabuilder-offline"; -// Add whichever assets you want to pre-cache here: -const PRECACHE_ASSETS = [ - '/assets/', - '/dados.csv' -] +importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js'); -// Listener for the install event - pre-caches our assets list on service worker install. -self.addEventListener('install', event => { - event.waitUntil((async () => { - const cache = await caches.open(CACHE_NAME); - cache.addAll(PRECACHE_ASSETS); - })()); +self.addEventListener("message", (event) => { + if (event.data && event.data.type === "SKIP_WAITING") { + self.skipWaiting(); + } }); -self.addEventListener('activate', event => { - event.waitUntil(self.clients.claim()); -}); - -self.addEventListener('fetch', event => { - event.respondWith(async () => { - const cache = await caches.open(CACHE_NAME); - - // match the request to our cache - const cachedResponse = await cache.match(event.request); - - // check if we got a valid response - if (cachedResponse !== undefined) { - // Cache hit, return the resource - return cachedResponse; - } else { - // Otherwise, go to the network - return fetch(event.request) - }; - }); -}); +workbox.routing.registerRoute( + new RegExp('/*'), + new workbox.strategies.StaleWhileRevalidate({ + cacheName: CACHE + }) +);