What is code-splitting?

Code-Splitting is a feature supported by bundlers like Webpack and Browserify which can create multiple bundles that can be dynamically loaded at runtime. The react project supports code splitting via dynamic import() feature.

For example, in the below code snippets, it will make moduleA.js and all its unique dependencies as a separate chunk that only loads after the user clicks the 'Load' button. moduleA.js

const moduleA = 'Hello';
export { moduleA };


import React, { Component } from 'react';
class App extends Component {
handleClick = () => {
.then(({ moduleA }) => {
// Use moduleA
.catch((err) => {
// Handle failure
render() {
return (
<button onClick={this.handleClick}>Load</button>
export default App;

Author of content
Edit this page

Made by Michael Sakhniuk