2021-07-21 15:28:56 +00:00
|
|
|
importScripts(
|
2021-09-24 18:17:50 +00:00
|
|
|
"https://storage.googleapis.com/workbox-cdn/releases/6.3.0/workbox-sw.js"
|
2021-07-21 15:28:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
workbox.setConfig({
|
2021-07-22 11:23:42 +00:00
|
|
|
debug: false,
|
2021-07-21 15:28:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// This will trigger the importScripts() for workbox.strategies and its dependencies:
|
|
|
|
const { precacheAndRoute, cleanupOutdatedCaches } = workbox.precaching;
|
|
|
|
const { setCacheNameDetails, clientsClaim } = workbox.core;
|
|
|
|
const { registerRoute } = workbox.routing;
|
|
|
|
const { googleFontsCache, imageCache, offlineFallback } = workbox.recipes;
|
|
|
|
const { StaleWhileRevalidate } = workbox.strategies;
|
2021-03-21 21:34:21 +00:00
|
|
|
|
|
|
|
// SETTINGS
|
|
|
|
|
|
|
|
// Claiming control to start runtime caching asap
|
|
|
|
clientsClaim();
|
|
|
|
|
|
|
|
// PRECACHING
|
|
|
|
|
2021-09-24 17:10:54 +00:00
|
|
|
const prefix = "appserver";
|
|
|
|
|
2021-03-21 21:34:21 +00:00
|
|
|
// Setting custom cache name
|
2021-09-24 17:10:54 +00:00
|
|
|
setCacheNameDetails({
|
|
|
|
prefix: prefix,
|
|
|
|
precache: "precache",
|
|
|
|
runtime: "runtime",
|
2021-09-24 18:17:50 +00:00
|
|
|
suffix: "v1.0.0",
|
2021-09-24 17:10:54 +00:00
|
|
|
});
|
2021-03-21 21:34:21 +00:00
|
|
|
|
|
|
|
// We inject manifest here using "workbox-build" in workbox-inject.js
|
2021-07-21 15:28:56 +00:00
|
|
|
const precachRoutes = self.__WB_MANIFEST;
|
|
|
|
|
|
|
|
precacheAndRoute(precachRoutes);
|
2021-03-21 21:34:21 +00:00
|
|
|
|
|
|
|
// Remove cache from the previous WB versions
|
|
|
|
cleanupOutdatedCaches();
|
|
|
|
|
|
|
|
// STATIC RESOURCES
|
|
|
|
|
2021-09-24 17:10:54 +00:00
|
|
|
googleFontsCache({ cachePrefix: `${prefix}-gfonts` });
|
2021-03-21 21:34:21 +00:00
|
|
|
|
|
|
|
// TRANSLATIONS
|
|
|
|
|
|
|
|
registerRoute(
|
|
|
|
({ url }) => url.pathname.indexOf("/locales/") !== -1,
|
|
|
|
// Use cache but update in the background.
|
|
|
|
new StaleWhileRevalidate({
|
|
|
|
// Use a custom cache name.
|
2021-09-24 17:10:54 +00:00
|
|
|
cacheName: `${prefix}-translation`,
|
2021-03-21 21:34:21 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
// CONTENT
|
|
|
|
|
2021-09-24 17:10:54 +00:00
|
|
|
imageCache({ cacheName: `${prefix}-images`, maxEntries: 60 });
|
2021-03-21 21:34:21 +00:00
|
|
|
|
|
|
|
// APP SHELL UPDATE FLOW
|
|
|
|
|
|
|
|
addEventListener("message", (event) => {
|
|
|
|
if (event.data && event.data.type === "SKIP_WAITING") {
|
|
|
|
self.skipWaiting();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// FALLBACK
|
|
|
|
|
|
|
|
offlineFallback({
|
|
|
|
pageFallback: "/static/offline/offline.html",
|
2021-03-24 08:45:58 +00:00
|
|
|
imageFallback: "/static/offline/offline.svg",
|
|
|
|
fontFallback: false,
|
2021-03-21 21:34:21 +00:00
|
|
|
});
|