mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: move assets
This commit is contained in:
parent
da1cb4ff9b
commit
5e6f599348
20 changed files with 11 additions and 326 deletions
|
|
@ -25,7 +25,7 @@ export function addGlobalListeners() {
|
|||
function registerServiceWorker() {
|
||||
"serviceWorker" in navigator &&
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker.register("../../sw.js").catch(err => {
|
||||
navigator.serviceWorker.register("../sw.js").catch(err => {
|
||||
console.error("ServiceWorker registration failed: ", err);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
77
src/sw.js
Normal file
77
src/sw.js
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
importScripts("https://storage.googleapis.com/workbox-cdn/releases/6.2.0/workbox-sw.js");
|
||||
|
||||
const {Route, registerRoute} = workbox.routing;
|
||||
const {CacheFirst, NetworkFirst} = workbox.strategies;
|
||||
const {CacheableResponsePlugin} = workbox.cacheableResponse;
|
||||
const {ExpirationPlugin} = workbox.expiration;
|
||||
|
||||
const DAY = 24 * 60 * 60;
|
||||
|
||||
const getPolitics = ({entries, days}) => {
|
||||
return [new CacheableResponsePlugin({statuses: [0, 200]}), new ExpirationPlugin({maxEntries: entries, maxAgeSeconds: days * DAY})];
|
||||
};
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.mode === "navigate",
|
||||
new NetworkFirst({
|
||||
networkTimeoutSeconds: 3,
|
||||
cacheName: "fmg-html",
|
||||
plugins: [new CacheableResponsePlugin({statuses: [0, 200]})]
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request, url}) => request.destination === "script" && !url.pathname.endsWith("min.js") && !url.pathname.includes("versioning.js"),
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-scripts",
|
||||
plugins: getPolitics({entries: 100, days: 30})
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.destination === "style",
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-stylesheets",
|
||||
plugins: getPolitics({entries: 100, days: 30})
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request, url}) => request.destination === "script" && url.pathname.endsWith("min.js"),
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-libs",
|
||||
plugins: getPolitics({entries: 100, days: 30})
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
new RegExp(".json$"),
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-json",
|
||||
plugins: getPolitics({entries: 100, days: 30})
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.destination === "image",
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-images",
|
||||
plugins: getPolitics({entries: 1000, days: 30})
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
new RegExp(".svg$"),
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-charges",
|
||||
plugins: getPolitics({entries: 1000, days: 30})
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
({request}) => request.destination === "font",
|
||||
new CacheFirst({
|
||||
cacheName: "fmg-fonts",
|
||||
plugins: getPolitics({entries: 200, days: 30})
|
||||
})
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue