PWA: cache documents
This commit is contained in:
parent
f1bfc2f3a6
commit
2ebb485473
@ -7,7 +7,7 @@ import { CacheFirst } from "workbox-strategies";
|
||||
|
||||
clientsClaim();
|
||||
|
||||
const staticTypes = ["image", "video", "audio", "script", "style", "font"];
|
||||
const staticTypes = ["image", "video", "audio", "script", "style", "font", "document"];
|
||||
registerRoute(
|
||||
({ request, url }) => url.origin === self.location.origin && staticTypes.includes(request.destination),
|
||||
new CacheFirst({
|
||||
@ -15,15 +15,6 @@ registerRoute(
|
||||
})
|
||||
);
|
||||
|
||||
// External media domains which have unique urls (never changing content) and can be cached forever
|
||||
const externalMediaHosts = ["void.cat", "nostr.build", "imgur.com", "i.imgur.com", "pbs.twimg.com", "i.ibb.co"];
|
||||
registerRoute(
|
||||
({ url }) => externalMediaHosts.includes(url.host),
|
||||
new CacheFirst({
|
||||
cacheName: "ext-content-hosts",
|
||||
})
|
||||
);
|
||||
|
||||
self.addEventListener("message", event => {
|
||||
if (event.data && event.data.type === "SKIP_WAITING") {
|
||||
self.skipWaiting();
|
||||
|
@ -1,5 +1,5 @@
|
||||
export function register() {
|
||||
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
registerValidSW("/service-worker.js");
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user