Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply 62 React and Next.js performance optimization rules from Vercel Engineering
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/bundle-preload.md
1---2title: Preload Based on User Intent3impact: MEDIUM4impactDescription: reduces perceived latency5tags: bundle, preload, user-intent, hover6---78## Preload Based on User Intent910Preload heavy bundles before they're needed to reduce perceived latency.1112**Example (preload on hover/focus):**1314```tsx15function EditorButton({ onClick }: { onClick: () => void }) {16const preload = () => {17if (typeof window !== 'undefined') {18void import('./monaco-editor')19}20}2122return (23<button24onMouseEnter={preload}25onFocus={preload}26onClick={onClick}27>28Open Editor29</button>30)31}32```3334**Example (preload when feature flag is enabled):**3536```tsx37function FlagsProvider({ children, flags }: Props) {38useEffect(() => {39if (flags.editorEnabled && typeof window !== 'undefined') {40void import('./monaco-editor').then(mod => mod.init())41}42}, [flags.editorEnabled])4344return <FlagsContext.Provider value={flags}>45{children}46</FlagsContext.Provider>47}48```4950The `typeof window !== 'undefined'` check prevents bundling preloaded modules for SSR, optimizing server bundle size and build speed.51