fix remote asset caching with workbox CacheableResponsePlugin

This commit is contained in:
Martti Malmi 2023-02-09 21:26:57 +02:00
parent 8a8ac6718f
commit 1067e31aed
3 changed files with 12 additions and 3 deletions

View File

@ -90,6 +90,7 @@
"styled-components": "^5.3.6",
"websocket-polyfill": "^0.0.3",
"workbox-background-sync": "^6.5.4",
"workbox-cacheable-response": "^6.5.4",
"workbox-expiration": "^6.5.4",
"workbox-routing": "^6.5.4",
"workbox-strategies": "^6.5.4"

View File

@ -1,5 +1,6 @@
import { getFiles, setupPrecaching, setupRouting } from 'preact-cli/sw';
import { BackgroundSyncPlugin } from 'workbox-background-sync';
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
import { ExpirationPlugin } from 'workbox-expiration';
import { registerRoute } from 'workbox-routing';
import { CacheFirst, NetworkFirst, NetworkOnly } from 'workbox-strategies';
@ -8,6 +9,7 @@ const bgSyncPlugin = new BackgroundSyncPlugin('apiRequests', {
maxRetentionTime: 14 * 24 * 60,
});
registerRoute(
({ request }) => request.method === 'POST',
new NetworkOnly({
@ -40,8 +42,11 @@ registerRoute(
new CacheFirst({
cacheName: 'scaled-images',
plugins: [
new CacheableResponsePlugin({
statuses: [0, 200],
}),
new ExpirationPlugin({
maxEntries: 1000,
maxEntries: 300,
maxAgeSeconds: 7 * 24 * 60 * 60,
purgeOnQuotaError: true,
}),
@ -55,8 +60,11 @@ registerRoute(
new CacheFirst({
cacheName: 'remote-assets',
plugins: [
new CacheableResponsePlugin({
statuses: [0, 200],
}),
new ExpirationPlugin({
maxEntries: 200,
maxEntries: 100,
maxAgeSeconds: 7 * 24 * 60 * 60,
purgeOnQuotaError: true,
}),

View File

@ -12792,7 +12792,7 @@ workbox-build@6.5.4:
workbox-sw "6.5.4"
workbox-window "6.5.4"
workbox-cacheable-response@6.5.4, workbox-cacheable-response@^6.5.3:
workbox-cacheable-response@6.5.4, workbox-cacheable-response@^6.5.3, workbox-cacheable-response@^6.5.4:
version "6.5.4"
resolved "https://registry.yarnpkg.com/workbox-cacheable-response/-/workbox-cacheable-response-6.5.4.tgz#a5c6ec0c6e2b6f037379198d4ef07d098f7cf137"
integrity sha512-DCR9uD0Fqj8oB2TSWQEm1hbFs/85hXXoayVwFKLVuIuxwJaihBsLsp4y7J9bvZbqtPJ1KlCkmYVGQKrBU4KAug==