How Deep is Your DOM? | Frontend at Scale - Deepstash
How Deep is Your DOM? | Frontend at Scale

How Deep is Your DOM? | Frontend at Scale

Curated from: frontendatscale.com

Ideas, facts & insights covering these topics:

4 ideas

·

25 reads

Explore the World's Best Ideas

Join today and uncover 100+ curated journeys from 50+ topics. Unlock access to our mobile app with extensive features.

Trees in the browserwoods

Trees in the browserwoods

Lighthouse warns us about large DOM sizes because they increase memory usage and can produce expensive style calculations . This can have a significant impact on user experience, especially for users on lower-end devices.

When we work with a tree data structure like the DOM, its depth has a lot to do with how fast operations such as lookups perform on them.

The deeper a tree goes, the more operations it could take to access one of its elements.

5

8 reads

Tall vs Wide Trees

Tall vs Wide Trees

A tree's height and balance impact efficiency and performance, as seen with Binary Search Trees. Consider self-balancing BSTs to maintain a minimum height and fast operations.

Deep DOM trees in CSS can be problematic. Large and nested trees result in expensive style recalculations, affecting performance and responsiveness.

  • To decrease issues with styling, keep the DOM tree shallow and wide
  • Self-balancing BSTs can also help reduce tree height and improve performance
  • With a shallow and wide DOM tree, style recalculations are quicker, improving app response time

🌳🌳🌳🌳

5

6 reads

Regular checkup

Regular checkup

You can measure DOM size and depth on your site using a tool like Lighthouse or PageSpeed Insights . If you want to quickly check how many elements you have on the page at any given time, you can run this on your browser’s console:

The main thing is to periodically check your DOM size and depth . I know this sounds obvious, but since we typically work with UI components or template partials that only expose us to a bit of HTML at a time, it’s easy to forget about how these bits of markup add up.

5

6 reads

CSS

CSS

Another thing that helps a lot is reducing the scope and complexity of your CSS selectors . This gives the browser an easier time finding the elements you’re trying to target and helps perform style recalculations much faster.

5

5 reads

IDEAS CURATED BY

traa

Director of Engineering @ Edgio. Love games, tech and people. In this order.

CURATOR'S NOTE

How the DOM tree size is actually affects your page load speed

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Personalized microlearning

100+ Learning Journeys

Access to 200,000+ ideas

Access to the mobile app

Unlimited idea saving

Unlimited history

Unlimited listening to ideas

Downloading & offline access

Supercharge your mind with one idea per day

Enter your email and spend 1 minute every day to learn something new.

Email

I agree to receive email updates