--- url: "https://web.dev/learn/performance/code-split-javascript" titulek: "Code-split JavaScript | web.dev" h1: "Code-split JavaScript Stay organized with collections Save and categorize content based on your preferences." popis: "Some resources are not crucial to a web page's initial load. JavaScript is one such resource that can be deferred until the time of need through a technique known as code splitting. By doing so, you can improve performance by lowering bandwidth and CPU contention—a critical consideration for improving both initial page load speed and input responsiveness during startup." jazyk: "en" kanonicka: "https://web.dev/learn/performance/code-split-javascript" drobecky: ["web.dev", "Resources", "Performance"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 02:41:53" znaku: 14843 slov: 2083 kodovani: "iso-8859-2" sha256: "7ec7d3be022a375f38eb9abd8dc05067885d1cd69e1561d0ceea285998b7d2fc" --- Code-split JavaScript Stay organized with collections Save and categorize content based on your preferences. Loading large JavaScript resources impacts page speed significantly. Splitting your JavaScript into smaller chunks and only downloading what is necessary for a page to function during startup can greatly improve your page's [load responsiveness](/articles/tbt), which in turn can improve your page's [Interaction to Next Paint (INP)](/articles/inp). As a page downloads, parses, and compiles large JavaScript files, it can become unresponsive for periods of time. The page elements are visible, as they are a part of a page's initial HTML and styled by CSS. However, because the JavaScript required to power those interactive elements—as well as other scripts loaded by the page—may be parsing and executing the JavaScript for them to function. The result is that the user may feel as though the interaction was significantly delayed, or even altogether broken. This often happens because the main thread is blocked, as JavaScript is parsed and compiled on the main thread. If this process takes too long, interactive page elements may not respond quickly enough to user input. One remedy for this is to load only the JavaScript you need for the page to function, while deferring other JavaScript to load later on through a technique known as code splitting. This module focuses on the latter of these two techniques. Reduce JavaScript parsing and execution during startup through code splitting [Lighthouse](https://developer.chrome.com/docs/lighthouse/overview/) throws a warning when [JavaScript execution takes longer than 2 seconds, and fails when it takes more than 3.5 seconds](https://developer.chrome.com/docs/lighthouse/performance/bootup-time/). Excessive JavaScript parsing and execution is a potential problem at *any* point in the page lifecycle, as it has the potential to increase an interaction's [*input delay*](/articles/optimize-input-delay) if the time at which the user interacts with the page coincides with the moment the main thread tasks responsible for processing and executing JavaScript are running. More than that, excessive JavaScript execution and parsing is particularly problematic during the initial page load, as this is the point in the page lifecycle that users are quite likely to interact with the page. In fact, [Total Blocking Time (TBT)](/articles/tbt)—a load responsiveness metric—is [highly correlated](https://almanac.httparchive.org/en/2022/performance#inp-and-tbt) with [INP](/articles/inp), suggesting that users have a high tendency to attempt interactions during the initial page load. The Lighthouse audit that reports the time spent executing each JavaScript file that your page requests is useful in that it can help you identify exactly which scripts may be candidates for [*code splitting*](/articles/reduce-javascript-payloads-with-code-splitting). You can then go further by using the [coverage tool](https://developer.chrome.com/docs/devtools/coverage/) in Chrome DevTools to identify exactly which parts of a page's JavaScript go unused during page load. Code splitting is a useful technique that can reduce a page's initial JavaScript payloads. It lets you split a JavaScript bundle into two parts: The JavaScript needed at page load, and therefore can't be loaded at any other time. Remaining JavaScript that can be loaded at a later point in time, most often at the point in which the user interacts with a given interactive element on the page. Code splitting can be done by using the [dynamic `import()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import) syntax. This syntax—unlike `