← Web Performance (Core Web Vitals) learning pathWeb Performance (Core Web Vitals) · Module 4 of 8
JavaScript cost
Every kilobyte of script must be downloaded, parsed and run.
📖 Key ideas
- JavaScript is expensive: on slow phones, parsing and running it can take longer than downloading it.
- Code splitting loads only the code a page needs, and loads the rest later.
- Use defer or async on scripts so they do not block the first render.
- Remove unused libraries and check bundle size with a bundle analyser.
- Break long tasks (over 50 ms) into smaller pieces to keep the page responsive.
💡 Real-life example: A heavy JavaScript bundle is like a long instruction manual handed to a waiter before serving: the food (your page) waits until reading is done.
BundleCombined JavaScript file built for the browser
Code splittingBreaking a bundle into parts loaded when needed
deferScript attribute that runs it after HTML is parsed
Long taskMain-thread work longer than 50 milliseconds