// CREDITS: https://github.com/umluizlima/flask-pwa/blob/master/app/static/sw.js // File Created by [Check Commits for Name] console.log('Hello from sw.js'); importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.2.0/workbox-sw.js'); if (workbox) { console.log(`Yay! Workbox is loaded 🎉`); workbox.precaching.precacheAndRoute([ { "url": "/", "revision": "1" } ]); workbox.routing.registerRoute( /\.(?:js|css)$/, workbox.strategies.staleWhileRevalidate({ cacheName: 'static-resources', }), ); workbox.routing.registerRoute( /\.(?:png|gif|jpg|jpeg|svg)$/, workbox.strategies.cacheFirst({ cacheName: 'images', plugins: [ new workbox.expiration.Plugin({ maxEntries: 60, maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days }), ], }), ); workbox.routing.registerRoute( new RegExp('https://fonts.(?:googleapis|gstatic).com/(.*)'), workbox.strategies.cacheFirst({ cacheName: 'googleapis', plugins: [ new workbox.expiration.Plugin({ maxEntries: 30, }), ], }), ); } else { console.log(`Boo! Workbox didn't load 😬`); }