setto.basspistol.com/_service-worker.js

41 lines
1,022 B
JavaScript
Raw Normal View History

2020-08-05 16:56:35 +02:00
// service-worker.js
// set names for both precache & runtime cache
workbox.core.setCacheNameDetails({
prefix: 'SettoPWA',
suffix: 'v1',
precache: 'precache',
runtime: 'runtime-cache'
});
// let Service Worker take control of pages ASAP
workbox.skipWaiting();
workbox.clientsClaim();
// let Workbox handle our precache list
workbox.precaching.precacheAndRoute(self.__precacheManifest);
// use `networkFirst` strategy for `*.html`, like all my posts
workbox.routing.registerRoute(
/\.html$/,
workbox.strategies.networkFirst()
);
2020-08-12 16:53:17 +02:00
// use `cacheFirst` strategy for images and static assets
2020-08-05 16:56:35 +02:00
workbox.routing.registerRoute(
2020-08-12 16:53:17 +02:00
/assets\/(img|icons|fonts|webfonts)/,
workbox.strategies.cacheFirst()
2020-08-05 16:56:35 +02:00
);
workbox.routing.registerRoute(
/videos/,
workbox.strategies.cacheFirst()
);
workbox.routing.registerRoute(
/images\/(posts|pages)/,
workbox.strategies.cacheFirst()
);
// third party files
workbox.routing.registerRoute(
/^https?:\/\/media.basspistol.com/,
workbox.strategies.staleWhileRevalidate()
);