perf(web): warm every primary route

This commit is contained in:
lingniu
2026-07-16 02:35:10 +08:00
parent d140a9782b
commit 7396544269
3 changed files with 21 additions and 11 deletions

View File

@@ -18,8 +18,9 @@ const importers: Record<RouteSection, () => Promise<RouteModule>> = {
const pendingModules = new Map<RouteSection, Promise<RouteModule>>();
const backgroundPreloadOrder: RouteSection[] = [
'monitor', 'tracks', 'history', 'statistics'
'monitor', 'vehicles', 'tracks', 'history', 'statistics', 'alerts', 'access', 'operations'
];
const backgroundPreloadBatchSize = 2;
function loadRoute(section: RouteSection) {
const pending = pendingModules.get(section);
@@ -84,11 +85,9 @@ export function scheduleIdleRoutePreloads({
const warmNext = () => {
if (cancelled) return;
const section = queue.shift();
if (!section) return;
void Promise.resolve()
.then(() => preload(`/${section}`))
.catch(() => undefined)
const batch = queue.splice(0, backgroundPreloadBatchSize);
if (!batch.length) return;
void Promise.allSettled(batch.map((section) => Promise.resolve().then(() => preload(`/${section}`))))
.finally(() => {
if (!cancelled) cancelScheduled = schedule(warmNext);
});