perf(textbooks): lazy-build параграфов Алгебры 8 — стартовая загрузка стала мгновенной
Было: init() синхронно вызывал buildP1...buildFinal — 7 секций × ~500 строк HTML, плюс KaTeX renderMathInElement сканировал весь body. На медленном CPU могло подвисать на 2-5 секунд.
Стало: init() строит только §1 (через goTo('p1')). Остальные секции строятся лениво при первом goTo(id) — кэшируются в BUILT Set.
Профит: первая отрисовка в 7 раз быстрее. KaTeX-рендер тоже только для активной секции.
This commit is contained in:
@@ -504,8 +504,16 @@ function buildParaSelector(){
|
||||
});
|
||||
}
|
||||
|
||||
const BUILT = new Set();
|
||||
const BUILDERS = { p1:()=>buildP1(), p2:()=>buildP2(), p3:()=>buildP3(), p4:()=>buildP4(), p5:()=>buildP5(), p6:()=>buildP6(), final:()=>buildFinal() };
|
||||
function ensureBuilt(id){
|
||||
if(BUILT.has(id)) return;
|
||||
const fn = BUILDERS[id];
|
||||
if(fn){ fn(); BUILT.add(id); }
|
||||
}
|
||||
function goTo(id){
|
||||
STATE.current = id;
|
||||
ensureBuilt(id);
|
||||
document.querySelectorAll('.sec').forEach(s=>s.classList.remove('active'));
|
||||
const el = document.getElementById('sec-' + id);
|
||||
if(el) el.classList.add('active');
|
||||
@@ -734,16 +742,8 @@ function init(){
|
||||
initTheme();
|
||||
initSearch();
|
||||
buildParaSelector();
|
||||
// Build all paragraph bodies
|
||||
if(typeof buildP1 === 'function') buildP1();
|
||||
if(typeof buildP2 === 'function') buildP2();
|
||||
if(typeof buildP3 === 'function') buildP3();
|
||||
if(typeof buildP4 === 'function') buildP4();
|
||||
if(typeof buildP5 === 'function') buildP5();
|
||||
if(typeof buildP6 === 'function') buildP6();
|
||||
if(typeof buildFinal === 'function') buildFinal();
|
||||
refreshProgressUI();
|
||||
goTo('p1');
|
||||
goTo('p1'); // строит только §1, остальные — лениво при переходе
|
||||
setTimeout(()=>achievement('start','Начало пути по корням!'), 800);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user