mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
perf: prefetch background chunk on page load from localStorage cache
- Add prefetchBackground() to registry — triggers dynamic import without creating React component - Call prefetch at module init in BackgroundRenderer using cached config from localStorage, before React renders - Background JS chunk starts downloading immediately instead of waiting for Suspense to trigger lazy() import
This commit is contained in:
@@ -3,7 +3,7 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import { brandingApi } from '@/api/branding';
|
||||
import type { AnimationConfig, BackgroundType } from '@/components/ui/backgrounds/types';
|
||||
import { DEFAULT_ANIMATION_CONFIG } from '@/components/ui/backgrounds/types';
|
||||
import { backgroundComponents } from '@/components/ui/backgrounds/registry';
|
||||
import { backgroundComponents, prefetchBackground } from '@/components/ui/backgrounds/registry';
|
||||
|
||||
const ANIMATION_CACHE_KEY = 'cabinet_animation_config';
|
||||
|
||||
@@ -16,6 +16,14 @@ function getCachedConfig(): AnimationConfig | null {
|
||||
}
|
||||
}
|
||||
|
||||
// Prefetch the background JS chunk immediately based on localStorage cache.
|
||||
// This starts the download before React even renders, so by the time
|
||||
// Suspense needs the component, the chunk is already loaded.
|
||||
const cachedConfig = getCachedConfig();
|
||||
if (cachedConfig?.enabled && cachedConfig.type && cachedConfig.type !== 'none') {
|
||||
prefetchBackground(cachedConfig.type);
|
||||
}
|
||||
|
||||
function setCachedConfig(config: AnimationConfig) {
|
||||
try {
|
||||
localStorage.setItem(ANIMATION_CACHE_KEY, JSON.stringify(config));
|
||||
|
||||
Reference in New Issue
Block a user