From cb233f4ccb75f8a5cddc382696e822a4bfffa5e4 Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Wed, 10 Jan 2024 22:15:58 +0200 Subject: [PATCH] cacheableresponse plugin fixes img sw cache --- packages/app/package.json | 1 + packages/app/src/service-worker.ts | 7 ++++++- yarn.lock | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index 46515828..2dbb919e 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -44,6 +44,7 @@ "use-long-press": "^3.2.0", "use-sync-external-store": "^1.2.0", "uuid": "^9.0.0", + "workbox-cacheable-response": "^7.0.0", "workbox-core": "^6.4.2", "workbox-expiration": "^7.0.0", "workbox-precaching": "^7.0.0", diff --git a/packages/app/src/service-worker.ts b/packages/app/src/service-worker.ts index 1fda3da9..416d160a 100644 --- a/packages/app/src/service-worker.ts +++ b/packages/app/src/service-worker.ts @@ -1,4 +1,6 @@ /// +import { CacheableResponsePlugin } from "workbox-cacheable-response"; + declare const self: ServiceWorkerGlobalScope & { __WB_MANIFEST: (string | PrecacheEntry)[]; }; @@ -53,6 +55,9 @@ registerRoute( ignoreVary: true, }, }), + new CacheableResponsePlugin({ + statuses: [0, 200], + }), ], }), ); @@ -61,7 +66,7 @@ registerRoute( ({ url }) => url.origin === "https://api.snort.social" && url.pathname.startsWith("/api/v1/preview"), new StaleWhileRevalidate({ cacheName: "preview-cache", - plugins: [new ExpirationPlugin({ maxAgeSeconds: 4 * 60 * 60 })], + plugins: [new ExpirationPlugin({ maxAgeSeconds: 24 * 60 * 60 })], }), ); diff --git a/yarn.lock b/yarn.lock index b604b739..129eebf0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3002,6 +3002,7 @@ __metadata: vite-plugin-pwa: ^0.17.0 vite-plugin-version-mark: ^0.0.10 vitest: ^0.34.6 + workbox-cacheable-response: ^7.0.0 workbox-core: ^6.4.2 workbox-expiration: ^7.0.0 workbox-precaching: ^7.0.0 @@ -11959,7 +11960,7 @@ __metadata: languageName: node linkType: hard -"workbox-cacheable-response@npm:7.0.0": +"workbox-cacheable-response@npm:7.0.0, workbox-cacheable-response@npm:^7.0.0": version: 7.0.0 resolution: "workbox-cacheable-response@npm:7.0.0" dependencies: