41 lines
995 B
JavaScript
41 lines
995 B
JavaScript
// 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()
|
|
);
|
|
|
|
// use `cacheFirst` strategy for images
|
|
workbox.routing.registerRoute(
|
|
/assets\/(img|icons|css)/,
|
|
workbox.strategies.networkFirst()
|
|
);
|
|
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()
|
|
); |