caching service worker
This commit is contained in:
46
sw.js
Normal file
46
sw.js
Normal file
@ -0,0 +1,46 @@
|
||||
importScripts(
|
||||
'https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js'
|
||||
);
|
||||
|
||||
if(workbox) {
|
||||
self.skipWaiting();
|
||||
workbox.core.clientsClaim();
|
||||
|
||||
workbox.routing.registerRoute(
|
||||
/\.(?:png|gif|jpg|jpeg|svg|webp|avif|gif)$/,
|
||||
new workbox.strategies.CacheFirst({
|
||||
cacheName: 'images-cache',
|
||||
plugins: [
|
||||
new workbox.expiration.ExpirationPlugin({
|
||||
maxEntries: 500,
|
||||
maxAgeSeconds: 365 * 24 * 60 * 60,
|
||||
}),
|
||||
],
|
||||
})
|
||||
);
|
||||
workbox.routing.registerRoute(
|
||||
/.*resources\/(semag|sppa).*/,
|
||||
new workbox.strategies.CacheFirst({
|
||||
cacheName: 'resources-cache',
|
||||
plugins: [
|
||||
new workbox.expiration.ExpirationPlugin({
|
||||
maxEntries: 100,
|
||||
maxAgeSeconds: 365 * 24 * 60 * 60,
|
||||
}),
|
||||
],
|
||||
})
|
||||
);
|
||||
|
||||
workbox.routing.registerRoute(
|
||||
/.*resources\/(games|apps)\.json$/,
|
||||
new workbox.strategies.StaleWhileRevalidate({
|
||||
cacheName: 'json-cache',
|
||||
plugins: [
|
||||
new workbox.expiration.ExpirationPlugin({
|
||||
maxAgeSeconds: 24 * 60 * 60,
|
||||
maxEntries: 2,
|
||||
}),
|
||||
],
|
||||
})
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user