EvoCalculator.Client2/apps/web/service-worker.ts

27 lines
603 B
TypeScript

import { CacheableResponsePlugin } from 'workbox-cacheable-response';
import { clientsClaim } from 'workbox-core';
import { registerRoute } from 'workbox-routing';
import { StaleWhileRevalidate } from 'workbox-strategies';
declare let self: ServiceWorkerGlobalScope;
const cacheName = 'pages-cache';
self.addEventListener('install', () => {
self.skipWaiting();
});
clientsClaim();
registerRoute(
({ request }) => request.destination === 'document',
new StaleWhileRevalidate({
cacheName,
plugins: [
new CacheableResponsePlugin({
statuses: [200],
}),
],
})
);