This commit is contained in:
Mateusz Gruszczyński
2026-09-01 11:36:11 +02:00
parent 3e3f8c3f19
commit 6207bc4de6
9 changed files with 29 additions and 20 deletions
+9 -2
View File
@@ -262,14 +262,21 @@ function renderLanguageOptions() {
async function loadLanguages() {
try {
const response = await fetch(withBase('/lang/index.json'), {cache: 'no-cache'});
// Language packs must never come from a stale Service Worker/browser cache.
// A cache-busting nonce is intentional: translations can change without the JS asset hash changing.
const languageNonce = Date.now().toString(36);
const languageUrl = path => {
const separator = String(path).includes('?') ? '&' : '?';
return `${withBase(path)}${separator}v=${languageNonce}`;
};
const response = await fetch(languageUrl('/lang/index.json'), {cache: 'no-store'});
if (!response.ok) throw new Error(`Language index HTTP ${response.status}`);
const manifest = await response.json();
const languages = Array.isArray(manifest.languages) ? manifest.languages : [];
if (!languages.some(item => item.code === DEFAULT_LANGUAGE)) throw new Error('Default English language pack is missing');
const loaded = await Promise.all(languages.map(async item => {
const packResponse = await fetch(withBase(item.path || `/lang/${encodeURIComponent(item.code)}.json`), {cache: 'no-cache'});
const packResponse = await fetch(languageUrl(item.path || `/lang/${encodeURIComponent(item.code)}.json`), {cache: 'no-store'});
if (!packResponse.ok) throw new Error(`Language ${item.code} HTTP ${packResponse.status}`);
const pack = await packResponse.json();
return {item, pack};