Lazy routes
Split route components usingcreateLazyRoute:
src/routes/posts/$postId.tsx
src/routes/posts/$postId.lazy.tsx
Code-based lazy routes
For code-based routing:src/routes/posts.lazy.tsx
Lazy route components
Lazy-load just the component:src/routes/Dashboard.tsx
What to split
Critical loader logic
Keep loaders in the main bundle for SSR:Heavy components
Split large component libraries:Route groups
Split entire route sections:Preloading strategies
Control when chunks are loaded:Manual preloading
Preload routes programmatically:Suspense boundaries
Control loading states during code splitting:Pending components
Show loading state while lazy chunks load:Bundle analysis
Analyze bundle sizes to find optimization opportunities:vite.config.ts
Route-level splitting
Ensure each route is in its own chunk:vite.config.ts
Dynamic imports
Lazy-load utilities and helpers:Best practices
Keep loaders in main bundle
Keep loaders in main bundle
Loaders should not be lazy-loaded - they need to run on the server.
Split per route
Split per route
Each route should be its own chunk for optimal caching.
Preload critical routes
Preload critical routes
Use preload=“intent” or preload=“viewport” for frequently accessed routes.
Use Suspense boundaries
Use Suspense boundaries
Wrap lazy routes in Suspense to show loading states.
Analyze your bundles
Analyze your bundles
Regularly check bundle sizes and split large chunks.
Performance tips
Target bundle size: Aim for chunks under 200KB. Larger chunks should be split further.
Next steps
File-based routing
Learn automatic route splitting
Vite plugin
Configure code splitting