mirror of
https://github.com/Unkn0wnCat/data-toolbox-site.git
synced 2025-07-14 11:17:15 +02:00
Update Service Worker files
This commit is contained in:
parent
ce7586bf13
commit
de44b2c0a8
1 changed files with 56 additions and 15 deletions
|
@ -9,9 +9,19 @@
|
||||||
|
|
||||||
import { clientsClaim } from 'workbox-core';
|
import { clientsClaim } from 'workbox-core';
|
||||||
import { ExpirationPlugin } from 'workbox-expiration';
|
import { ExpirationPlugin } from 'workbox-expiration';
|
||||||
|
import {CacheableResponsePlugin} from 'workbox-cacheable-response';
|
||||||
import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching';
|
import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching';
|
||||||
import { registerRoute } from 'workbox-routing';
|
import { registerRoute } from 'workbox-routing';
|
||||||
import { StaleWhileRevalidate } from 'workbox-strategies';
|
import { StaleWhileRevalidate, CacheFirst } from 'workbox-strategies';
|
||||||
|
import {setCacheNameDetails} from 'workbox-core';
|
||||||
|
import {BackgroundSyncPlugin} from 'workbox-background-sync';
|
||||||
|
|
||||||
|
setCacheNameDetails({
|
||||||
|
prefix: 'kevins-toolbox',
|
||||||
|
suffix: 'v1',
|
||||||
|
precache: 'precache',
|
||||||
|
runtime: 'runtime'
|
||||||
|
});
|
||||||
|
|
||||||
clientsClaim();
|
clientsClaim();
|
||||||
|
|
||||||
|
@ -45,21 +55,52 @@ registerRoute(
|
||||||
},
|
},
|
||||||
createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html')
|
createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html')
|
||||||
);
|
);
|
||||||
|
|
||||||
// An example runtime caching route for requests that aren't handled by the
|
|
||||||
// precache, in this case same-origin .png requests like those from in public/
|
|
||||||
registerRoute(
|
registerRoute(
|
||||||
// Add in any other file extensions or routing criteria as needed.
|
({request}) => request.destination === 'image',
|
||||||
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
|
new CacheFirst({
|
||||||
new StaleWhileRevalidate({
|
|
||||||
cacheName: 'images',
|
cacheName: 'images',
|
||||||
plugins: [
|
plugins: [
|
||||||
// Ensure that once this runtime cache reaches a maximum size the
|
new CacheableResponsePlugin({
|
||||||
// least-recently used images are removed.
|
statuses: [0, 200],
|
||||||
new ExpirationPlugin({ maxEntries: 50 }),
|
}),
|
||||||
|
new ExpirationPlugin({
|
||||||
|
maxEntries: 60,
|
||||||
|
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
registerRoute(
|
||||||
|
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('translation.json'),
|
||||||
|
new StaleWhileRevalidate({
|
||||||
|
cacheName: 'translations',
|
||||||
|
plugins: [
|
||||||
|
new ExpirationPlugin({ maxEntries: 5 }),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
registerRoute(
|
||||||
|
({url}) => url.origin === 'https://fonts.googleapis.com' ||
|
||||||
|
url.origin === 'https://fonts.gstatic.com',
|
||||||
|
new StaleWhileRevalidate({
|
||||||
|
cacheName: 'google-fonts',
|
||||||
|
plugins: [
|
||||||
|
new ExpirationPlugin({maxEntries: 20}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
registerRoute(
|
||||||
|
({request}) => request.destination === 'script' ||
|
||||||
|
request.destination === 'style',
|
||||||
|
new StaleWhileRevalidate({
|
||||||
|
plugins: [
|
||||||
|
new BackgroundSyncPlugin()
|
||||||
|
]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
// This allows the web app to trigger skipWaiting via
|
// This allows the web app to trigger skipWaiting via
|
||||||
// registration.waiting.postMessage({type: 'SKIP_WAITING'})
|
// registration.waiting.postMessage({type: 'SKIP_WAITING'})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue