/* global workbox */ /* eslint-env serviceworker */ importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0-beta.0/workbox-sw.js'); // The final service worker will have this array added by the // `gulp serviceWorker` task. workbox.precaching.precacheAndRoute([]); workbox.skipWaiting(); workbox.clientsClaim(); // Cache Google Fonts workbox.routing.registerRoute( /https:\/\/fonts.(?:googleapis|gstatic)\.com.*$/, workbox.strategies.staleWhileRevalidate({ cacheName: 'google-fonts', plugins: [ new workbox.expiration.Plugin({ maxEntries: 30, }), ], }) ); // Cache any additional CSS and JS files. workbox.routing.registerRoute( /\.(?:js|css)$/, workbox.strategies.staleWhileRevalidate({ cacheName: 'static-resources', }) ); // Cache Images. workbox.routing.registerRoute( /\.(?:png|gif|jpg|jpeg|svg)$/, workbox.strategies.cacheFirst({ cacheName: 'images', plugins: [ new workbox.expiration.Plugin({ maxEntries: 30, maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days }), ], }) );