Created
April 9, 2021 14:24
-
-
Save Gummibeer/99004a456c745e3582da4f5d730c668d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {registerRoute} from 'workbox-routing'; | |
import {StaleWhileRevalidate} from 'workbox-strategies'; | |
import {CacheableResponsePlugin} from 'workbox-cacheable-response'; | |
import {CacheFirst} from 'workbox-strategies'; | |
import {ExpirationPlugin} from 'workbox-expiration'; | |
self.addEventListener("message", (event) => { | |
if (event.data && event.data.type === "SKIP_WAITING") { | |
self.skipWaiting(); | |
} | |
}); | |
registerRoute( | |
({request}) => request.destination === 'script', | |
new StaleWhileRevalidate({ | |
cacheName: 'scripts', | |
}), | |
); | |
registerRoute( | |
({request}) => request.destination === 'style', | |
new StaleWhileRevalidate({ | |
cacheName: 'styles', | |
}), | |
); | |
registerRoute( | |
({request}) => request.destination === 'image', | |
new CacheFirst({ | |
cacheName: 'images', | |
plugins: [ | |
new CacheableResponsePlugin({ | |
statuses: [0, 200], | |
}), | |
new ExpirationPlugin({ | |
maxEntries: 100, | |
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days | |
}), | |
], | |
}), | |
); | |
registerRoute( | |
new RegExp('/*'), | |
new StaleWhileRevalidate({ | |
cacheName: 'pwa-offline' | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment