prefetch on navigation + auto-preload current language data

This commit is contained in:
catarrh committed 2026-08-01 21:49:01 +03:00
1 parent 465e2664cc
commit 4a1e22d68b
2 files changed
+41 -1

No files matched your search

+16 -1
View File
@@ -411,7 +411,6 @@ export class CalendarView {
if (stored) {
const settings = JSON.parse(stored);
let cuFont = settings.cuFont || '';
// Migrate old usePonomarFont
if (settings.usePonomarFont !== undefined) {
cuFont = settings.usePonomarFont ? 'Ponomar' : '';
}
@@ -422,6 +421,14 @@ export class CalendarView {
return this.language === 'cu' ? 'font-ponomar' : '';
}
/** Prefetch lives data for a given month to warm the cache. */
private prefetchMonth(month: number): void {
const mm = String(month).padStart(2, '0');
const lang = this.language;
const url = `/data/${lang}/lives/${mm}.json`;
DataCache.fetch(url).catch(() => {});
}
/** Lightweight dRank computation for calendar grid highlighting */
private getDayRank(date: JDate, julianYear: number): number {
const month = date.getMonth();
@@ -932,5 +939,13 @@ export class CalendarView {
svcPanel.innerHTML = `<p class="text-sm text-navy-light italic">${this.t.loading}</p>`;
}
}
// Prefetch current and adjacent month's lives data for faster navigation
const currentMonth = this.currentDate.getMonth();
const prevMonth = currentMonth <= 1 ? 12 : currentMonth - 1;
const nextMonth = currentMonth >= 12 ? 1 : currentMonth + 1;
this.prefetchMonth(currentMonth);
this.prefetchMonth(prevMonth);
this.prefetchMonth(nextMonth);
}
}