Fixing Lighthouse “Optimize DOM size” Warnings on Long Lists
Lighthouse's "Optimize DOM size" warning (listed as Optimize DOM size in English) goes away when you either reduce the number of items on a page, or use the CSS content-visibility: auto to defer rendering of items that are off screen. It appears on pages that show thousands of same-shaped items, such as article lists, product lists, or histories, when the layout work needed to open the page is heavy. In my test of a 3,000-item list page, reducing the page to 20 items and also reducing nesting cut the element count from 33,005 to 87, and the warning did not appear in any of the three runs. In contrast, keeping the 3,000 items and only reducing the nested divs inside each item left the warning in place, even though the element count dropped to about a third.
The test environment was Ubuntu 24.04, Node.js 22, Lighthouse 13.6.0 (the npm package), and Chrome for Testing 153. I ran Lighthouse from the command line with the default settings (mobile), limited to the performance category, and ran each page three times. I served the pages from a small server on my test machine (localhost:8080). I used Playwright 1.63.0 to measure heights and take screenshots of the report. I did not test the Lighthouse panel or the Performance panel in Chrome DevTools, PageSpeed Insights, virtual scrolling in frameworks such as React (for example react-window), or any live public site.
- 1. Lighthouse 13 does not flag based on element count alone
- 2. What happened when 3,000 diary entries were on one page
- 3. Reducing nested divs alone did not clear the warning
- 4. Reducing the number of items per page
- 5. If all items must stay on one page, use content-visibility
- 6. Comparison of the fixes tried
Lighthouse 13 does not flag based on element count alone
The behavior of this warning changed in Lighthouse 13. The explanation of the Lighthouse 12 audit "Avoid an excessive DOM size" says that a warning appears when the body has more than about 800 nodes, and an error when it has more than about 1,400. The same page says this audit moved to the "Optimize DOM size" insight in Lighthouse 13. In the Lighthouse 13.6.0 source code, the new audit (dom-size-insight) is defined as a replacement for the old one (dom-size).
The new audit does not use the element count to decide. Chrome's explanation of the "Optimize DOM size" insight says that a warning appears only when there is a large layout or style recalculation that takes more than 40 milliseconds. A large layout is one that processes more than 100 layout objects (roughly the number of elements). A large style recalculation is one that affects more than 300 elements. The Lighthouse 13.6.0 code (DOMSize.js) uses the same thresholds of 40 milliseconds, 100, and 300. So even with tens of thousands of elements, there is no warning if the layout finishes in under 40 milliseconds.
There is also no effect on the score. In the default configuration file for Lighthouse 13.6.0, the weight of this audit is 0.
What happened when 3,000 diary entries were on one page
The test page showed 3,000 cat diary entries, one per day. Each entry was written with several levels of nested divs that added nothing visually.
<li><div class="card"><div class="card-inner"><div class="card-body"><div class="row"><div class="col"><span class="date">2021-01-01</span><span class="name">たま</span></div></div><div class="row"><div class="col"><p class="note">窓辺で昼寝をした</p></div></div></div></div></div></li>
I ran Lighthouse and used a small script (summarize.mjs) to extract the scores, the metrics, and the results of this audit from the JSON output. From the traces saved with --save-assets, I used another script (events.mjs) to find layouts and style recalculations that took 40 milliseconds or more, using the same thresholds as DOMSize.js (40 milliseconds, 100, and 300). This is the large updates line at the end. Lighthouse with --quiet prints nothing, so the output below comes from the two scripts. In the 15 runs reported in this article, the Lighthouse warning appeared only in the runs where this script found a large layout (informative). In the runs where it found none, the result was numeric.
$ npx lighthouse http://localhost:8080/before/ --only-categories=performance --save-assets --output=json --output=html --output-path=./out/before-2 --chrome-flags="--headless=new --no-sandbox" --quiet
$ node summarize.mjs out/before-2.report.json
lighthouseVersion: 13.6.0 requestedUrl: http://localhost:8080/before/
performance score: 97
FCP: 0.6 s (score 1) LCP: 0.6 s (score 1) SI: 0.7 s (score 1) TBT: 190 ms (score 0.91) CLS: 0 (score 1)
dom-size-insight: score=1 scoreDisplayMode=informative title="Optimize DOM size" numericValue=33005 metricSavings={"INP":0}
- Total elements: 33005
- DOM depth: 9 (<span class="date">)
- Most children: 3000 (<ul>)
$ node events.mjs out/before-2-0.trace.json
large updates (>=40ms): Layout 63.1ms dirtyObjects=37457
The page had 33,005 elements in total. The deepest element was nine levels down, and the element with the most children was the <ul> holding the 3,000 entries. In this run, a layout took 63.1 milliseconds and the warning appeared (scoreDisplayMode=informative). With the Japanese locale (--locale=ja), the audit title is shown in Japanese, equivalent to "Optimize DOM size", and the table rows are labeled in Japanese, equivalent to "total element count", "DOM depth", and "maximum number of children".
In the HTML report, the warning appeared under "Insights" with a gray circle. As the label "Unscored" indicates, it does not count toward the score.

However, the same page did not always trigger the warning. In one of the three runs reported in this article, the longest layout took 35.2 milliseconds and no warning appeared (large updates (>=40ms): none). The three runs before that, using the same procedure, all showed the warning. Across all six runs, 5 showed the warning, and in those runs the large layouts took 45.6 to 63.1 milliseconds. On this page, the layout time straddled the 40-millisecond threshold, between 35.2 and 63.1 milliseconds, so the result changed from run to run.
Reducing nested divs alone did not clear the warning
First, I reduced the nesting for each entry while keeping all 3,000 entries. I used the same CSS classes and wrote each entry with just the li and three elements inside it.
<li class="card"><span class="date">2021-01-01</span><span class="name">たま</span><p class="note">窓辺で昼寝をした</p></li>
The element count dropped from 33,005 to 12,005, and the depth dropped from nine levels to four. The warning still appeared in all six runs: the three reported in this article and the three run before them.
lighthouseVersion: 13.6.0 requestedUrl: http://localhost:8080/flat/
performance score: 99
FCP: 0.6 s (score 1) LCP: 0.6 s (score 1) SI: 0.7 s (score 1) TBT: 140 ms (score 0.95) CLS: 0 (score 1)
dom-size-insight: score=1 scoreDisplayMode=informative title="Optimize DOM size" numericValue=12005 metricSavings={"INP":0}
- Total elements: 12005
- DOM depth: 4 (<span class="date">)
- Most children: 3000 (<ul>)
large updates (>=40ms): Layout 48.5ms dirtyObjects=24008
The layouts that exceeded 40 milliseconds took between 48.5 and 72.6 milliseconds. On this page, reducing the elements per entry was not enough to bring the time for laying out all 3,000 entries below 40 milliseconds. The official explanation lists reducing nesting as a fix, but on this page it was not sufficient by itself.
Reducing the number of items per page
Next, I kept the reduced-nesting markup but limited each page to 20 diary entries, with a "next 20 entries" link at the end. I also prepared the second page (./page/2/) as a separate HTML file.
<li class="card"><span class="date">2021-01-20</span><span class="name">しろ</span><p class="note">ごはんを全部食べた</p></li>
</ul>
<p><a href="./page/2/">次の20件</a></p>
The page now had 87 elements, and no layout exceeded 40 milliseconds. The warning did not appear in any of the three runs.
lighthouseVersion: 13.6.0 requestedUrl: http://localhost:8080/paged/
performance score: 100
FCP: 0.6 s (score 1) LCP: 0.6 s (score 1) SI: 0.6 s (score 1) TBT: 10 ms (score 1) CLS: 0 (score 1)
dom-size-insight: score=1 scoreDisplayMode=numeric title="Optimize DOM size" numericValue=87 metricSavings={"INP":0}
- Total elements: 87
- DOM depth: 4 (<span class="date">)
- Most children: 20 (<ul>)
large updates (>=40ms): none
In the report, this audit showed a green circle and moved to the "Passed audits" section.

The explanation of the Lighthouse 12 audit also recommends leaving elements that are not visible on first render out of the initial HTML, and creating them only when they are needed, for example on scroll or a button click. Splitting the list into pages, or adding a "Show more" button that appends items, follows the same idea.
If all items must stay on one page, use content-visibility
If you want to keep all the items on one page and still let users find them with the browser's find-in-page feature, the CSS content-visibility: auto is an option. MDN's explanation of content-visibility says that an element with auto skips rendering its contents while it is away from the viewport. The skipped contents remain in the DOM and the accessibility tree, so they are still matched by find-in-page and reached by tabbing.
I added the following line to .card on the page with deep nesting (the version before any changes). contain-intrinsic-size is the placeholder height used while rendering is skipped.
.card { content-visibility: auto; contain-intrinsic-size: auto 52px; }
The element count stayed at 33,005, but no layout exceeded 40 milliseconds, and the warning did not appear in any of the three runs. CLS was also 0.
lighthouseVersion: 13.6.0 requestedUrl: http://localhost:8080/cv/
performance score: 100
FCP: 0.6 s (score 1) LCP: 0.6 s (score 1) SI: 0.6 s (score 1) TBT: 20 ms (score 1) CLS: 0 (score 1)
dom-size-insight: score=1 scoreDisplayMode=numeric title="Optimize DOM size" numericValue=33005 metricSavings={"INP":0}
- Total elements: 33005
- DOM depth: 9 (<span class="date">)
- Most children: 3000 (<ul>)
large updates (>=40ms): none
Including padding and border in the placeholder height makes CLS worse
I also tested a page where the placeholder height was 70px, the full height of one diary entry including its padding and border. The warning again disappeared in all three runs, but CLS was 0.138 in all three runs, and the score dropped to 94–95.
lighthouseVersion: 13.6.0 requestedUrl: http://localhost:8080/cv-70/
performance score: 95
FCP: 0.6 s (score 1) LCP: 0.6 s (score 1) SI: 0.6 s (score 1) TBT: 50 ms (score 1) CLS: 0.138 (score 0.79)
I extracted the LayoutShift entries from the trace with a small node -e script. Entries lower on the page were laid out at 88px, then shrank to their actual height of 70px.
LayoutShift score=0.1378737988925575 old h=88 -> new h=70, old h=88 -> new h=70, old h=88 -> new h=70, old h=88 -> new h=70, old h=88 -> new h=70
88px is the 70px placeholder plus the top and bottom padding (8px each) and the border (1px each). The height written in contain-intrinsic-size was treated as the height of the content, excluding padding and border.
I measured the height of one diary entry by opening the page in Playwright with the same Chrome build that Lighthouse uses, using Lighthouse's mobile settings (412px wide, 823px tall, deviceScaleFactor 1.75).
$ node measure.cjs
chrome 153.0.8010.12: card heights (all cards, distinct values)=70px box-sizing=content-box computed height=52px padding=8px 8px border=1px 1px
before: document height=234126px
cv-70: document height=287676px
cv: document height=234126px
One entry was 70px including padding and border, and 52px for the content alone. With a placeholder of 52px, the total page height on first load matched the page without content-visibility (before) at 234,126px. With 70px, it was 287,676px, which made the page longer by that amount.
For contain-intrinsic-size, use the content height measured in a real browser (excluding padding and border). Do not stop once the DOM size warning is gone. Check CLS as well.
The measured height also depended on how Playwright launched the browser. With Playwright's default chromium.launch(), one entry measured 64px (46px of content). When I tried 46px first on a page with 2,000 entries, CLS was 0.047 in all three runs. The 52px value above was measured again with executablePath pointing to the same Chrome executable that Lighthouse launched. For reference, MDN's explanation of contain-intrinsic-size says that the length given here is used until the element is first rendered.
Comparison of the fixes tried
These are the results for each page, from the three runs reported in this article.
| Page | Total elements | DOM depth | Runs with warning | CLS |
|---|---|---|---|---|
| Before (3,000 items, deeply nested) | 33,005 | 9 | 2 of 3 | 0 |
| Reduced nesting (3,000 items) | 12,005 | 4 | 3 of 3 | 0 |
| 20 items per page (reduced nesting) | 87 | 4 | 0 of 3 | 0 |
| content-visibility (placeholder 70px) | 33,005 | 9 | 0 of 3 | 0.138 |
| content-visibility (placeholder 52px) | 33,005 | 9 | 0 of 3 | 0 |
This Lighthouse 13 warning is not based on counting elements. It looks at how long the layout and style calculations take when the page opens. As the table shows, if the calculation time stays at or above 40 milliseconds, the warning remains even after reducing the element count. When the amount of work done at once is reduced, the warning disappears, even if the element count stays the same.





