Performance: Creating routes
MEDIUM IMPACT
This affects the initial page load speed and navigation responsiveness by determining how routes are matched and components are loaded.
import { lazy, Suspense } from 'react'; const Home = lazy(() => import('./routes/Home')); const About = lazy(() => import('./routes/About')); export const routes = [ { path: '/', element: <Suspense fallback={<div>Loading...</div>}><Home /></Suspense> }, { path: '/about', element: <Suspense fallback={<div>Loading...</div>}><About /></Suspense> } ];
import Home from './routes/Home'; import About from './routes/About'; export const routes = [ { path: '/', element: <Home /> }, { path: '/about', element: <About /> } ];
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eager loading all routes | Low (few nodes initially) | 1 reflow on load | High paint cost due to large bundle | [X] Bad |
| Lazy loading route components | Low (few nodes initially) | 1 reflow on route change | Lower paint cost on initial load | [OK] Good |