Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

fix(PWA): add i18n cache rules to serve translations offline

Smaug67395a12e8312bf2
diff --git a/frontend/app/sw.ts b/frontend/app/sw.ts
index 450d10d6..00268b8a 100644
--- a/frontend/app/sw.ts
+++ b/frontend/app/sw.ts
@@ -1,7 +1,7 @@
/// <reference lib="webworker" />
import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
import { registerRoute, NavigationRoute } from 'workbox-routing';
-import { NetworkFirst } from 'workbox-strategies';
+import { NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies';
import { clientsClaim } from 'workbox-core';
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
import { ExpirationPlugin } from 'workbox-expiration';
@@ -35,6 +35,23 @@ registerRoute(
),
);
+// ─── i18n Translations cache ─────────────────────────────────────────────────
+registerRoute(
+ ({ url }) => url.pathname.includes('/_i18n/'),
+ new StaleWhileRevalidate({
+ cacheName: 'i18n-cache',
+ plugins: [
+ new CacheableResponsePlugin({
+ statuses: [0, 200],
+ }),
+ new ExpirationPlugin({
+ maxEntries: 50,
+ maxAgeSeconds: 10 * 24 * 60 * 60,
+ }),
+ ],
+ }),
+);
+
// ─── API cache ───────────────────────────────────────────────────────────────
registerRoute(
({ url }) => url.origin === __BASE_API__ && !url.pathname.startsWith('/api/backup/'),