Framework-Specific Splitting Features
What you'll learn: How modern React frameworks provide built-in code splitting that differs from manual React.lazy() and import() approaches.
While you can manually split code with dynamic imports and React.lazy(), modern frameworks like Next.js, Remix, and Vite offer framework-specific splitting features that handle much of the complexity automatically—and often more intelligently.
Next.js Dynamic Imports
Next.js extends React's lazy() with next/dynamic, adding server-side rendering support and loading state customization:
import dynamic from 'next/dynamic';
const HeavyChart = dynamic(() => import('./HeavyChart'), {
loading: () => <p>Loading chart...</p>,
ssr: false // Client-only rendering
});
Next.js also automatically splits code at page boundaries—each route gets its own bundle without any configuration.
Remix Route Modules
Remix treats every route file as an automatic split point. You don't import routes—Remix's file-based router handles splitting:
routes/
index.tsx // Separate bundle
dashboard.tsx // Separate bundle
settings.tsx // Separate bundle
Remix also prefetches route bundles on link hover, making navigation feel instant.
Vite's Code Splitting
Vite uses Rollup under the hood and automatically splits vendor code from application code. It also supports manual chunk configuration for granular control:
// vite.config.js
build: {
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom']
}
}
}
}
Why Framework Features Matter
These framework-specific approaches handle challenges manual splitting doesn't: SSR compatibility, prefetching strategies, optimal chunk sizing, and cache invalidation. They're battle-tested solutions that balance bundle size with user experience.
Key Takeaway: Framework-specific code splitting features automate route-based splits, handle SSR gracefully, and include prefetching strategies that manual React.lazy() doesn't provide—use them when available instead of reinventing the wheel.