mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-16 17:31:24 +01:00
cache html with NetworkFirst strategy
This commit is contained in:
parent
2327aa980c
commit
32e8570794
1 changed files with 11 additions and 2 deletions
13
sw.js
13
sw.js
|
|
@ -1,16 +1,25 @@
|
|||
importScripts("https://storage.googleapis.com/workbox-cdn/releases/6.2.0/workbox-sw.js");
|
||||
|
||||
const {Route, registerRoute} = workbox.routing;
|
||||
const {CacheFirst} = workbox.strategies;
|
||||
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: [200]}), new ExpirationPlugin({maxEntries: entries, maxAgeSeconds: days * DAY})];
|
||||
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({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue