Code Splitting Routes with Lazy Loading
Learn how to split each route's code into a separate bundle loaded on demand, reducing the app's initial load size.
Code splitting routes means bundling each route's component (and its dependencies) into its own separate JavaScript chunk that's only downloaded when the user actually navigates to that route, rather than including every possible page's code in one large initial bundle. This directly reduces the amount of JavaScript the browser must download, parse, and execute before the user sees the first page.
Route-based code splitting is like a streaming service that only downloads the episode you're actually about to watch instead of the entire series' video files upfront — you get a brief loading spinner the first time you open a new episode (route), but you never pay the bandwidth cost for episodes you never watch.