Dev.Lib
arrow_backBack to Blogs
LEVEL_011.5June 27, 20261 min read

Code splitting strategies

Frontend Fundamentals

Split by route, feature, or component — trade initial bundle size vs waterfall of chunk requests.

Summary

Split by route, feature, or component — trade initial bundle size vs waterfall of chunk requests. Route-level splits align with navigation; component-level splits need Suspense/fallback UX. Preload critical route chunks on intent (hover/focus). Avoid splitting so aggressively that HTTP overhead dominates.

Code example

import { lazy, Suspense } from 'react';

const Dashboard = lazy(() => import('./Dashboard'));

function App() {
  return (
    <Suspense fallback={<Spinner />}>
      <Dashboard />
    </Suspense>
  );
}

Key points

  • Split by route, feature, or component — trade initial bundle size vs waterfall of chunk requests.
  • Route-level splits align with navigation; component-level splits need Suspense/fallback UX.
  • Preload critical route chunks on intent (hover/focus).
  • Avoid splitting so aggressively that HTTP overhead dominates.

Further reading

Related concepts