Menu

Our 79 pages contain 3,083 divs and 3,053 script tags, and after hydration the scripts win
📰

Our 79 pages contain 3,083 divs and 3,053 script tags, and after hydration the scripts win

DEV Community: html·Daniel Pertu·about 22 hours ago
#rCEk7G61
#devto2#devto#dev#elements#pages
Reading 0:00
15s threshold

Lighthouse has an audit called "Avoid an excessive DOM size" that starts complaining at 1,500 elements, 32 levels of depth or 60 children on one parent. I have never once seen it fire on our site , so I never thought about the shape of the DOM at all. This week I measured it properly: every element on all 79 pages in the sitemap , the depth of every branch, every text node and every comment node.

const all = [ . . . document . querySelectorAll ( '*' ) ] ; // elements let max = 0 ; ( function walk ( el , d ) { if ( d > max ) max = d ; for ( const c of el . children ) walk ( c , d + 1 ) ; } ) ( document . documentElement , 1 ) ; const tw = document . createTreeWalker ( document . body , NodeFilter . SHOW_TEXT | NodeFilter .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.