import {precacheAndRoute, createHandlerBoundToURL} from 'workbox-precaching'; import {NavigationRoute, registerRoute} from 'workbox-routing'; import {StaleWhileRevalidate, CacheFirst} from 'workbox-strategies'; import {CacheableResponsePlugin} from 'workbox-cacheable-response' import {ExpirationPlugin} from 'workbox-expiration'; console.log('Hello from sw.js'); // See https://developer.chrome.com/docs/workbox/migration/migrate-from-v4/ for guide to changes made console.log('Yay! Workbox is loaded 🎉'); precacheAndRoute(self.__WB_MANIFEST || []); const handler = createHandlerBoundToURL('/index.html'); const navigationRoute = new NavigationRoute(handler // , {allowlist: [...], denylist: [...],} ); registerRoute(navigationRoute); registerRoute( /\.(?:png|jpg|jpeg|svg|gif)$/, new CacheFirst({ plugins: [ new CacheableResponsePlugin({ statuses: [0, 200] }) ] }) ); registerRoute( /\.(?:js|css)$/, new StaleWhileRevalidate({ cacheName: 'static-resources', }) ); registerRoute( new RegExp('https://fonts.(?:googleapis|gstatic).com/(.*)'), new CacheFirst({ cacheName: 'google-fonts', plugins: [ new ExpirationPlugin({ maxEntries: 30 }), new CacheableResponsePlugin({ statuses: [0, 200] }) ] }) ); self.addEventListener('message', event => { if (!event.data) { return; } switch (event.data) { case 'skipWaiting': self.skipWaiting(); break; default: // NOOP break; } });