Why do sites that strictly enforce a 200KB JavaScript budget sometimes still fail INP when they rely heavily on CSS animations and complex DOM trees?
Answered 3-minute answer rooted in 3 pages
Because a JavaScript budget limits how much script is downloaded, and INP is also made of rendering work that no byte budget measures. Every interaction ends with the browser producing the next frame: recalculating styles, laying out the page and painting it. web.dev calls that span presentation delay, and it grows with the size of the DOM and the amount of layout an interaction triggers. A 150KB bundle that toggles a class on a large, deeply nested page can still produce a frame that takes hundreds of milliseconds to present.
Where the time goes in an interaction
web.dev’s INP article divides each interaction into three phases. A JavaScript budget mostly acts on the first two:
| Phase | What fills it | Does a JS byte budget control it? |
|---|---|---|
| Input delay | Other tasks running when the input arrives | Partly; less script means fewer long tasks |
| Processing duration | The event handler callbacks | Partly; small handlers can still trigger expensive work |
| Presentation delay | Style, layout and paint for the next frame | No |
The INP optimization guide describes presentation delay as the span from when an interaction’s callbacks finish “up to the point at which the browser is able to paint the next frame”.
Why DOM size matters
The same guide is direct about the relationship: “when DOMs get very large, rendering work tends to scale with increasing DOM size”, and “large DOMs do require more work to render than small DOMs”. The relationship “isn’t a linear one”, but the direction is clear. A single class change on a container can force style recalculation for thousands of descendants, then layout for everything whose size or position depends on them.
For example, imagine a product listing page with a few thousand cards, each with nested wrappers, badges and price blocks. Opening a filter panel changes one class on the page wrapper. The handler takes a few milliseconds; the style recalculation and layout of every card take far longer. The JavaScript budget was met, and the interaction still exceeds 200 milliseconds.
How animations and layout patterns add to it
Layout thrashing. The INP guide describes layout thrashing, which it also calls forced synchronous layout, as a problem “where layout occurs synchronously”. It happens when code reads layout values (such as an element’s size) after changing styles, forcing the browser to calculate layout immediately and repeatedly inside the handler.
Animations that change layout properties. web.dev’s animations guide advises avoiding “any property that triggers layout or paint unless it’s absolutely necessary”, and treats transform and opacity as the exceptions. An animation that changes width, height or position adds rendering work to every frame it runs in, including the frame an interaction is waiting for.
Content-heavy updates on interaction. Expanding a menu that inserts hundreds of nodes, or re-rendering a whole list for a small change, puts large DOM changes into the presentation phase.
What to budget instead of only bytes
- Measure presentation delay from real visits. RUM attribution for INP shows which phase is slow. If presentation delay dominates, the fix is in rendering, not in the bundle.
- Reduce DOM size on heavy templates. Flatten wrappers, paginate or virtualize long lists, and add content to the DOM when needed rather than all at once. The INP guide notes some DOMs cannot be reduced much, and suggests
content-visibilityfor content far from the viewport. - Avoid layout reads after writes in handlers. Group style changes and read layout values before changing them, not after.
- Animate properties that avoid layout, such as transforms and opacity, instead of width, height or position.
- Keep a JavaScript budget, and add rendering checks to it. A byte budget catches one cause. A test that measures interaction latency on the heaviest template catches the others.
A JavaScript budget is a useful control for download and parse cost. INP is a responsiveness metric, and responsiveness also depends on how much work the page asks the browser to do after each interaction.
Answers that share these roots
- How should large single-page applications restructure event handlers to reduce INP without sacrificing interactivity on complex filtering interfaces? shares 2 pages
- Why can replacing synchronous JavaScript with requestAnimationFrame callbacks sometimes increase INP rather than decrease it? shares 2 pages
- What is the mechanism by which total JavaScript payload size affects INP even when the initial page load appears fast and LCP is within the good threshold? shares 2 pages
- How does Interaction to Next Paint differ mechanistically from First Input Delay in what it captures about main-thread responsiveness? shares 1 page
Leave a Reply