28 lines
554 B
TypeScript
28 lines
554 B
TypeScript
import { clientsClaim } from 'workbox-core';
|
|
import { ExpirationPlugin } from 'workbox-expiration';
|
|
import { registerRoute } from 'workbox-routing';
|
|
import { CacheFirst } from 'workbox-strategies';
|
|
|
|
declare let self: ServiceWorkerGlobalScope;
|
|
|
|
const cacheName = 'my-cache';
|
|
|
|
self.addEventListener('install', () => {
|
|
self.skipWaiting();
|
|
});
|
|
|
|
clientsClaim();
|
|
|
|
registerRoute(
|
|
/\/(unlimited)?$/u,
|
|
new CacheFirst({
|
|
cacheName,
|
|
plugins: [
|
|
new ExpirationPlugin({
|
|
maxAgeSeconds: 1 * 60,
|
|
maxEntries: 8,
|
|
}),
|
|
],
|
|
})
|
|
);
|