Fix guides · Performance

How to fix “Optimize DOM size”: pages with too many elements

Very large pages make every style change and layout slow, so taps feel sluggish. How to trim them on Shopify, WordPress, Webflow, Wix, Squarespace and Next.js.

Time to fix
1–3 hours
Skill needed
Developer
Who notices
Visitors on phones: scrolling and taps feel slow

Why it matters

The DOM is the browser's model of every element on your page. The more elements, and the more deeply they're nested, the longer the browser takes each time it recalculates styles or layout.

Large pages usually come from content that's built but hidden: mega menus (often duplicated for mobile and desktop), filter panels, cart drawers, pop-ups, long product grids and page-builder wrappers inside wrappers.

“A large DOM can increase the duration of style calculations and layouts, impacting page responsiveness. A large DOM also increases memory usage.”

Chrome: Optimize DOM size insight

Before you start

  • Your report shows the total number of elements, the deepest nesting, and the element with the most children. The last one usually points straight at the cause: a menu, a grid or a list.
  • Chrome only fails this check when a single style or layout update takes longer than 40 ms, so a big page that stays responsive may pass.

Fix it on your platform

Shopify

  1. Build filter panels, cart drawers and dialogs only when a visitor first opens them, not on every page load.
  2. Show fewer products per collection page and paginate the rest.
  3. Check your menu: some themes output the full mega menu twice, once for desktop and once for mobile.

WordPress

  1. Page builders nest many wrapper elements. Check whether yours has a newer, lighter layout option, or move key pages to the block editor.
  2. Show fewer posts or products per page, and trim very large menus.
  3. Remove widgets and sidebar content that visitors don't use.

Webflow

  1. Remove empty or unnecessary wrapper divs, and reuse classes instead of adding extra elements just for styling.
  2. Limit how many items Collection Lists show, and paginate long ones.
  3. Avoid duplicating navigation or sections for different breakpoints; adjust the same elements per breakpoint instead.

Wix

  1. Keep pages simple and remove content you don't need, as Wix recommends.
  2. Move heavy elements such as galleries, videos and store widgets to separate pages or lower down.

Squarespace

  1. Squarespace suggests no more than 60 blocks per page, and no more than 50 images per gallery.
  2. Split pages that cover more than one topic into separate pages.
  3. On blog landing pages, show excerpts instead of full posts.

Next.js

  1. For long lists, render only what's on screen with a windowing library such as react-window, or paginate.
  2. Render dialogs, drawers and menus only when they're open, rather than hiding them with CSS.
Render only when open
{isOpen && <CartDrawer onClose={() => setOpen(false)} />}

Any other site

  1. Remove wrappers that exist only for styling; CSS grid and flexbox rarely need them.
  2. Build hidden content (menus, dialogs, tabs) when it's first opened, and paginate long lists.
  3. Use content-visibility: auto on long sections further down the page so the browser can skip their layout until they're near.
CSS
.article-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 800px;
}

“Filter panels, cart drawers, and dialogs add thousands of DOM nodes even when closed. Build their DOM only when the user first opens them.”

Shopify: Theme performance best practices

Check that it's fixed

  • Re-run your StudioLNC audit: the element count should drop, and the insight should no longer flag slow style or layout updates.
  • Check menus, filters and drawers still open and work.

Find every issue like this on your site

Free audit of performance, accessibility, SEO and security, with fixes for your platform.