sw caching for nostr.json and images
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Martti Malmi 2023-12-26 21:33:22 +02:00
parent d82c7957be
commit 9d2b867552
3 changed files with 27 additions and 1 deletions

View File

@ -43,6 +43,7 @@
"use-sync-external-store": "^1.2.0",
"uuid": "^9.0.0",
"workbox-core": "^6.4.2",
"workbox-expiration": "^7.0.0",
"workbox-precaching": "^7.0.0",
"workbox-routing": "^6.4.2",
"workbox-strategies": "^6.4.2"

View File

@ -7,10 +7,34 @@ import { NostrLink, NostrPrefix, TLVEntryType, encodeTLVEntries, tryParseNostrLi
import { formatShort } from "@/Number";
import { defaultAvatar, hexToBech32 } from "@/SnortUtils";
import { clientsClaim } from "workbox-core";
import { registerRoute } from "workbox-routing";
import { CacheFirst, StaleWhileRevalidate } from "workbox-strategies";
import { PrecacheEntry, precacheAndRoute } from "workbox-precaching";
import { ExpirationPlugin } from "workbox-expiration";
precacheAndRoute(self.__WB_MANIFEST);
clientsClaim();
registerRoute(
({ url }) => url.pathname.endsWith("/.well-known/nostr.json"),
new StaleWhileRevalidate({
cacheName: "nostr-json-cache",
plugins: [new ExpirationPlugin({ maxAgeSeconds: 4 * 60 * 60 })],
}),
);
// Cache images from any domain
registerRoute(
// Match any image request regardless of the origin
({ request }) => request.destination === "image",
new CacheFirst({
cacheName: "image-cache",
plugins: [
new ExpirationPlugin({
maxEntries: 100,
}),
],
}),
);
self.addEventListener("message", event => {
if (event.data && event.data.type === "SKIP_WAITING") {

View File

@ -2996,6 +2996,7 @@ __metadata:
vite-plugin-version-mark: ^0.0.10
vitest: ^0.34.6
workbox-core: ^6.4.2
workbox-expiration: ^7.0.0
workbox-precaching: ^7.0.0
workbox-routing: ^6.4.2
workbox-strategies: ^6.4.2
@ -11583,7 +11584,7 @@ __metadata:
languageName: node
linkType: hard
"workbox-expiration@npm:7.0.0":
"workbox-expiration@npm:7.0.0, workbox-expiration@npm:^7.0.0":
version: 7.0.0
resolution: "workbox-expiration@npm:7.0.0"
dependencies: