--- url: "https://web.dev/articles/script-evaluation-and-long-tasks" titulek: "Script evaluation and long tasks | web.dev" h1: "Script evaluation and long tasks Stay organized with collections Save and categorize content based on your preferences." popis: "When loading scripts, it takes time for the browser to evaluate them prior to execution, which can cause long tasks. Learn how script evaluation works, and what you can do to keep it from causing long tasks during page load." jazyk: "en" kanonicka: "https://web.dev/articles/script-evaluation-and-long-tasks" drobecky: ["web.dev", "Resources", "How to optimize INP"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 22:29:42" znaku: 15695 slov: 2354 kodovani: "iso-8859-2" sha256: "00e4b7a2262ee2c9c98659b093e965e55e2836353def9d3b40e04ab2b77bfe7f" --- Script evaluation and long tasks Stay organized with collections Save and categorize content based on your preferences. When loading scripts, it takes time for the browser to evaluate them prior to execution, which can cause long tasks. Learn how script evaluation works, and what you can do to keep it from causing long tasks during page load. Jeremy Wagner When it comes to optimizing [Interaction to Next Paint (INP)](/articles/inp), most of the advice you'll encounter is to optimize interactions themselves. For example, in the [optimize long tasks guide](/articles/optimize-long-tasks), techniques such as yielding with `setTimeout` and others are discussed. These techniques are beneficial, as they allow the main thread some breathing room by avoiding long tasks, which can allow more opportunities for interactions and other activity to run sooner, rather than if they had to wait for a single long task. However, what about the long tasks that come from loading scripts themselves? These tasks can interfere with user interactions and affect a page's INP during load. This guide will explore how browsers handle tasks kicked off by script evaluation, and look into what you may be able to do to break up script evaluation work so that your main thread can be more responsive to user input while the page is loading. What is script evaluation? If you've profiled an application that ships a lot of JavaScript, you may have seen long tasks where the culprit is labeled **Evaluate Script**. Script evaluation work as shown in the performance profiler in Chrome DevTools. In this case, the work is enough to cause a long task that blocks the main thread from taking on other work—including tasks that drive user interactions. Script evaluation is a necessary part of executing JavaScript in the browser, as JavaScript is compiled [just-in-time before execution](https://en.wikipedia.org/wiki/Just-in-time_compilation). When a script is evaluated, it is first parsed for errors. If the parser doesn't find errors, the script is then compiled into [bytecode](https://en.wikipedia.org/wiki/Bytecode), and then can continue onto execution. Though necessary, script evaluation can be problematic, as users may try to interact with a page shortly after it initially renders. However, just because a page has *rendered* doesn't mean that the page has finished *loading*. Interactions that take place during load can be delayed because the page is busy evaluating scripts. While there's no guarantee that an interaction can take place at this point in time—as a script responsible for it may not have loaded yet—there could be interactions dependent on JavaScript that *are* ready, or the interactivity doesn't depend on JavaScript at all. The relationship between scripts and the tasks that evaluate them How tasks responsible for script evaluation are kicked off depends on whether the script you're loading is loaded with a typical `