Performance

Code splitting

Breaking a site's JavaScript into smaller pieces so each page loads only the code it needs.

By Nick Irmo · Updated

What Code splitting means

Without code splitting, visitors may download code for the whole site just to read one page. Splitting keeps pages lighter and more responsive. Frameworks like Next.js do much of this automatically.

Why it matters for your website

Loading every feature's code on every page makes visitors download a lot they never use, which slows pages and can delay how fast buttons respond. Splitting code means each page loads only what it needs, improving speed and Core Web Vitals, especially on phones.

Example

A real estate site loads its heavy map and mortgage calculator code only on listing pages, so the homepage and blog stay light.

Tips

  • Load large features, like maps or chat widgets, only on pages that use them.
  • Use your framework's built-in route-based splitting where available.
  • Check bundle sizes regularly with your build tool's analysis report.

Common mistakes

  • Splitting code into so many tiny files that requests pile up.
  • Lazy loading code needed for content above the fold, which delays the first view.

Questions about Code splitting

What is Code splitting?
Breaking a site's JavaScript into smaller pieces so each page loads only the code it needs.
Do frameworks like Next.js do code splitting automatically?
Yes. Next.js and many modern frameworks split code by page automatically. You can split further with dynamic imports for heavy components.
Does code splitting help SEO?
Indirectly. Smaller JavaScript loads can improve page speed and responsiveness, which supports a better user experience and Core Web Vitals.

Tell us what the site needs to do.

Share a few details and a budget range. We reply within one business day with a plan, a platform recommendation and a fixed quote.