error page, sw

This commit is contained in:
Martti Malmi 2024-01-10 14:07:44 +02:00
parent 7be4b0bd18
commit 90b15ee668
3 changed files with 31 additions and 11 deletions

View File

@ -9,7 +9,7 @@ const ErrorPage = () => {
console.error(error);
return (
<div className="main-content page">
<div className="p-2">
<h4>
<FormattedMessage defaultMessage="An error has occured!" id="FfYsOb" />
</h4>
@ -21,15 +21,11 @@ const ErrorPage = () => {
}}>
<FormattedMessage defaultMessage="Clear cache and reload" id="HWbkEK" />
</AsyncButton>
{
<pre>
{JSON.stringify(
error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : error,
undefined,
" ",
)}
</pre>
}
<h5>{error.message}</h5>
<div className="my-2">{error.message}</div>
<pre className="my-2 whitespace-pre-wrap">
{error.stack}
</pre>
</div>
);
};

View File

@ -15,6 +15,23 @@ import { formatShort } from "@/Utils/Number";
precacheAndRoute(self.__WB_MANIFEST);
clientsClaim();
// cache everything in current domain /assets because precache doesn't seem to include everything
registerRoute(
({ url }) => url.origin === location.origin && url.pathname.startsWith("/assets"),
new StaleWhileRevalidate({
cacheName: "assets-cache",
plugins: [
new ExpirationPlugin({
maxEntries: 200,
matchOptions: {
ignoreVary: true,
}
}),
],
}),
);
registerRoute(
({ url }) => url.pathname.endsWith("/.well-known/nostr.json"),
new StaleWhileRevalidate({
@ -32,13 +49,16 @@ registerRoute(
plugins: [
new ExpirationPlugin({
maxEntries: 200,
matchOptions: {
ignoreVary: true,
}
}),
],
}),
);
registerRoute(
({ url }) => url.pathname.endsWith("api/v1/preview"),
({ 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 })],

View File

@ -18,6 +18,10 @@ export default defineConfig({
enabled: true,
type: "module",
},
workbox: {
globPatterns: ['**/*.{js,html,wasm,woff,woff2,ttf,svg,png,jpg,jpeg,webp,ico,json}'],
sourcemap: true,
}
}),
visualizer({
open: true,