From 7ebd1ee285cb589c72b00d29cba4c855137b629b Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Mon, 29 Jun 2026 04:46:33 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0]=20i18n.js=20=EC=B4=88=EA=B8=B0=ED=99=94=20?= =?UTF-8?q?=EC=8B=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20DOM=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EB=B0=A9=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 현재 문서의 언어(`document.documentElement.lang`)를 `currentLang`의 초기값으로 사용하여 초기 로딩 시 기본 언어가 한국어일 때 발생하는 불필요한 DOM 업데이트를 방지합니다. --- .jules/bolt.md | 3 +++ i18n.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index f74ef2f..213f4b0 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,3 +1,6 @@ ## 2024-06-20 - Unnecessary initial DOM updates for default language **Learning:** The simple static i18n implementation runs `node.textContent = dict[node.dataset.i18n]` for every translatable node on the initial script load, even when the HTML is already written in the target language (Korean). This creates unnecessary layout/paint operations and blocking time on the main thread for elements that don't need text changes. **Action:** Always check if the current value matches the desired value before updating the DOM (`node.textContent !== newText`), and add early exits when setting state to the same value to avoid redundant DOM traversal and writes. +## 2026-06-22 - Prevent redundant DOM queries on initial language set +**Learning:** The simple static i18n implementation was scanning the entire document to set translations even when the pre-rendered document language matched the user's preferred language. This happened because `currentLang` was initially `null`, causing the early return `if (currentLang === lang) return;` to fail on the initial page load. +**Action:** Always initialize language state variables using existing document attributes (`document.documentElement.lang`) if available, to ensure early-return checks correctly skip redundant work when the page is already in the target state. diff --git a/i18n.js b/i18n.js index 2393774..e801724 100644 --- a/i18n.js +++ b/i18n.js @@ -308,7 +308,7 @@ let langButtons = null; let metaDesc = null; let ogDesc = null; let footerLogo = null; -let currentLang = null; +let currentLang = document.documentElement.lang || "ko"; function setLanguage(lang) { if (currentLang === lang) return; // Skip if already in the requested language