All you need to know about JavaScript code splitting

JavaScript code splitting

Modern sites often combine all of their JavaScript into a single, large main.js script. This regularly contains the scripts for all your pages or routes, even if users only need a small portion for the page they're viewing. 

When JavaScript is served this way, the loading performance of your web pages can suffer – especially with responsive web design on mobile devices. So let's fix it by implementing JavaScript code splitting (make sure you also see our selection of CSS and JavaScript tutorials).

Thank you for reading 5 articles this month* Join now for unlimited access

Enjoy your first month for just £1 / $1 / €1

*Read 5 free articles per month without a subscription

Join now for unlimited access

Try first month for just £1 / $1 / €1

Addy is an engineering manager with the Chrome team at Google. His day-to-day job is leading a speed team who are dedicated to making the web fast. Their projects include Lighthouse.
Read more
A black Dell Latitude 9440 2-in-1 laptop
How to make a laptop faster
A desktop with a colourful portfolio on screen
How to create an online portfolio: Steps to curating your own corner of the web
little marbles in marble run
Why simplicity matters in UX and digital design
No code game engines; a cartoon flea, cartoon people and cartoon rally car
The best no code game engines recommended by leading indie devs
Photograph of laptop with Shopify sticker, on table beside coffee mug, with woman on her phone out of focus in background
How to use Shopify: tips for beginners
404 pages: LEGO
The best 404 pages for clever web design inspiration
Latest in Javascript
Speed up JavaScript
21 steps to super speedy JavaScript
Angular 8
What's inside Angular 8?
brain.js neural network
Use brain.js to build a neural network
Explore data visualisation with p5.js
Explore data visualisation with p5.js
WebGL 3D
Create a WebGL 3D landing page
JavaScript code splitting
All you need to know about JavaScript code splitting
Latest in How to
Venusaur art
How to paint Pokémon's Venusaur in Photoshop
Babiru DaVinci Resolve colour tips; a red creature in armour, it has a large toothy grin, in the background is a cyberpunk style city
How to achieve a bold cinematic look in animation, using DaVinci Resolve and Fusion Studio
Making Babiru, DaVinci Resolve and Unreal Engine; A tense and visually striking digital scene showcases a character poised with a glowing knife just before a dramatic confrontation, evoking themes of danger and anticipation in a cyberpunk environment.
Colour grading advice: how DaVinci Resolve Studio and Fusion Studio were harnessed for Babiru
Gesture drawing: all you need to know plus ways to practise in 2 and 5 minutes
How to draw a male figure
drawing of a naked woman with someone drawing it
How to draw a female figure