Code splitting in JavaScript

Nov 20, 2020 • ☕️ 1 min read

Code splitting is a technique used by module bundlers to split your code into various smaller bundles which can be loaded on demand or in parallel.

The main purpose is to minimize the amount of scripts that needs to be loaded, parsed, compiled, and executed to result in faster page load times.

Code splitting can be achieved at different levels — component, route, library — by using proposal syntax dynamic imports, 3rd-party libraries, bundler plugins, or framework features.

Popular bundlers have built-in support for splitting your bundles using dynamic imports syntax with almost zero configuration. (Read more at Webpack, with Babel, Parcel, etc.)

React supports code splitting out of the box with React.lazy at component level, but no server-side rendering (SSR) and library splitting.

Loadable-components is a library for loading components with dynamic imports, similar to React.lazy but has support for SSR and library splitting.

Related Posts

Node object-relational mappers (ORMs)

Notable object-relational mapping libraries for Node.js and relational database systems

What is static rendering?

Static rendering is a strategy that eagerly generates a separate HTML file for each URL ahead of time at build time

Cracking the Frontend Interview, Part 4: JavaScript

JavaScript is the heart of web development, be prepared to be asked multiple confusing advanced concepts about it during frontend interview

How hard could it be to become an indie maker?

Being a maker is all about building something that solves a problem, or brings happiness to other people