sw caching for nostr.json and images
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
d82c7957be
commit
9d2b867552
@ -43,6 +43,7 @@
|
|||||||
"use-sync-external-store": "^1.2.0",
|
"use-sync-external-store": "^1.2.0",
|
||||||
"uuid": "^9.0.0",
|
"uuid": "^9.0.0",
|
||||||
"workbox-core": "^6.4.2",
|
"workbox-core": "^6.4.2",
|
||||||
|
"workbox-expiration": "^7.0.0",
|
||||||
"workbox-precaching": "^7.0.0",
|
"workbox-precaching": "^7.0.0",
|
||||||
"workbox-routing": "^6.4.2",
|
"workbox-routing": "^6.4.2",
|
||||||
"workbox-strategies": "^6.4.2"
|
"workbox-strategies": "^6.4.2"
|
||||||
|
@ -7,10 +7,34 @@ import { NostrLink, NostrPrefix, TLVEntryType, encodeTLVEntries, tryParseNostrLi
|
|||||||
import { formatShort } from "@/Number";
|
import { formatShort } from "@/Number";
|
||||||
import { defaultAvatar, hexToBech32 } from "@/SnortUtils";
|
import { defaultAvatar, hexToBech32 } from "@/SnortUtils";
|
||||||
import { clientsClaim } from "workbox-core";
|
import { clientsClaim } from "workbox-core";
|
||||||
|
import { registerRoute } from "workbox-routing";
|
||||||
|
import { CacheFirst, StaleWhileRevalidate } from "workbox-strategies";
|
||||||
import { PrecacheEntry, precacheAndRoute } from "workbox-precaching";
|
import { PrecacheEntry, precacheAndRoute } from "workbox-precaching";
|
||||||
|
import { ExpirationPlugin } from "workbox-expiration";
|
||||||
|
|
||||||
precacheAndRoute(self.__WB_MANIFEST);
|
precacheAndRoute(self.__WB_MANIFEST);
|
||||||
clientsClaim();
|
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 => {
|
self.addEventListener("message", event => {
|
||||||
if (event.data && event.data.type === "SKIP_WAITING") {
|
if (event.data && event.data.type === "SKIP_WAITING") {
|
||||||
|
@ -2996,6 +2996,7 @@ __metadata:
|
|||||||
vite-plugin-version-mark: ^0.0.10
|
vite-plugin-version-mark: ^0.0.10
|
||||||
vitest: ^0.34.6
|
vitest: ^0.34.6
|
||||||
workbox-core: ^6.4.2
|
workbox-core: ^6.4.2
|
||||||
|
workbox-expiration: ^7.0.0
|
||||||
workbox-precaching: ^7.0.0
|
workbox-precaching: ^7.0.0
|
||||||
workbox-routing: ^6.4.2
|
workbox-routing: ^6.4.2
|
||||||
workbox-strategies: ^6.4.2
|
workbox-strategies: ^6.4.2
|
||||||
@ -11583,7 +11584,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"workbox-expiration@npm:7.0.0":
|
"workbox-expiration@npm:7.0.0, workbox-expiration@npm:^7.0.0":
|
||||||
version: 7.0.0
|
version: 7.0.0
|
||||||
resolution: "workbox-expiration@npm:7.0.0"
|
resolution: "workbox-expiration@npm:7.0.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
Reference in New Issue
Block a user