|
1 | 1 | /* eslint-env serviceworker */ |
2 | 2 | /* eslint-disable no-restricted-globals */ |
3 | 3 |
|
4 | | -// "editor-app-v1" is replaced with the package version at build time (see webpack.config.js) |
| 4 | +// "editor-app-v1" and "editor-translations-v1" are replaced with the package version at build time (see webpack.config.js) |
5 | 5 | const APP_CACHE = "editor-app-v1"; |
| 6 | +const TRANSLATIONS_CACHE = "editor-translations-v1"; |
6 | 7 | const PYODIDE_CACHE = "pyodide-v0.26.2"; |
7 | 8 |
|
8 | 9 | // Minimal set of assets to pre-cache on install |
@@ -37,7 +38,7 @@ self.addEventListener("activate", (event) => { |
37 | 38 | caches.keys().then((keys) => |
38 | 39 | Promise.all( |
39 | 40 | keys |
40 | | - .filter((key) => key !== APP_CACHE && key !== PYODIDE_CACHE) |
| 41 | + .filter((key) => key !== APP_CACHE && key !== TRANSLATIONS_CACHE && key !== PYODIDE_CACHE) |
41 | 42 | .map((key) => { |
42 | 43 | console.log("[SW] Deleting old cache:", key); |
43 | 44 | return caches.delete(key); |
@@ -123,6 +124,12 @@ self.addEventListener("fetch", (event) => { |
123 | 124 | return; |
124 | 125 | } |
125 | 126 |
|
| 127 | + // Translation files get their own cache so they can be evicted independently of the app shell |
| 128 | + if (url.origin === self.location.origin && url.pathname.includes("/translations/")) { |
| 129 | + event.respondWith(networkFirst(event.request, TRANSLATIONS_CACHE)); |
| 130 | + return; |
| 131 | + } |
| 132 | + |
126 | 133 | // Same-origin app assets are network-first so users get fresh content online |
127 | 134 | if (url.origin === self.location.origin) { |
128 | 135 | event.respondWith(networkFirst(event.request, APP_CACHE)); |
|
0 commit comments