mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-23 04:21:24 +01:00
register service worker
This commit is contained in:
parent
02e0669282
commit
f5683ab8d3
2 changed files with 72 additions and 0 deletions
7
main.js
7
main.js
|
|
@ -13,6 +13,13 @@ const TIME = DEBUG || !PRODUCTION;
|
|||
const WARN = true;
|
||||
const ERROR = true;
|
||||
|
||||
// register service worker
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker.register("/sw.js");
|
||||
});
|
||||
}
|
||||
|
||||
// if map version is not stored, clear localStorage and show a message
|
||||
if (rn(localStorage.getItem("version"), 1) !== rn(version, 1)) {
|
||||
localStorage.clear();
|
||||
|
|
|
|||
65
sw.js
Normal file
65
sw.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
importScripts("https://storage.googleapis.com/workbox-cdn/releases/6.2.0/workbox-sw.js");
|
||||
|
||||
const {Route, registerRoute} = workbox.routing;
|
||||
const {CacheFirst, StaleWhileRevalidate} = workbox.strategies;
|
||||
const {CacheableResponsePlugin} = workbox.cacheableResponse;
|
||||
const {ExpirationPlugin} = workbox.expiration;
|
||||
|
||||
const DAY = 24 * 60 * 60;
|
||||
const THIRTY_DAYS = DAY * 30;
|
||||
|
||||
registerRoute(
|
||||
({request, url}) => request.destination === "script" && !url.pathname.endsWith("min.js"),
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: "fmg-scripts",
|
||||
plugins: [new CacheableResponsePlugin({statuses: [200]}), new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: THIRTY_DAYS})]
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.destination === "style",
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: "fmg-stylesheets",
|
||||
plugins: [new CacheableResponsePlugin({statuses: [200]}), new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: THIRTY_DAYS})]
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request, url}) => request.destination === "script" && url.pathname.endsWith("min.js"),
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-libs",
|
||||
plugins: [new CacheableResponsePlugin({statuses: [200]}), new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: THIRTY_DAYS})]
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
new RegExp(".json$"),
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-json",
|
||||
plugins: [new CacheableResponsePlugin({statuses: [200]}), new ExpirationPlugin({maxEntries: 100, maxAgeSeconds: THIRTY_DAYS})]
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.destination === "image",
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-images",
|
||||
plugins: [new CacheableResponsePlugin({statuses: [200]}), new ExpirationPlugin({maxEntries: 1000, maxAgeSeconds: THIRTY_DAYS})]
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
new RegExp(".svg$"),
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-charges",
|
||||
plugins: [new CacheableResponsePlugin({statuses: [200]}), new ExpirationPlugin({maxEntries: 1000, maxAgeSeconds: THIRTY_DAYS})]
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.destination === "font",
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-fonts",
|
||||
plugins: [new CacheableResponsePlugin({statuses: [200]}), new ExpirationPlugin({maxEntries: 200, maxAgeSeconds: THIRTY_DAYS})]
|
||||
})
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue