Files
developer-roadmap/src/data/question-groups/full-stack/content/code-splitting.md
T
2025-01-29 15:49:48 +00:00

543 B

Code splitting breaks a large application into smaller bundles that are loaded only when needed.

Benefits:

  • Reduces initial load time by loading only essential code and downloading the rest when needed.
  • Improves performance for slower networks by allowing webapp use much sooner.

Example using React's lazy and Suspense:

const LazyComponent = React.lazy(() => import('./Component'));

function App() {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <LazyComponent />
    </Suspense>
  );
}