Avoid an excessive DOM size: 4 tools and 10 techniques
When building a website, keeping an eye on the DOM size is essential. An excessively large DOM can lead to slower load times and a poor user experience.
In this blog, we will explore 4 tools and 10 effective techniques to help you avoid an excessive DOM size and optimize the performance of your website. Implementing these strategies can improve your site’s speed and usability, providing a better experience for your users.
Let’s dive into it!
Table of Content
- What is DOM size and why does it matter?
- Why does the “Avoid an excessive DOM size” warning happen?
- The Impact of Excessive DOM Size
- Tools for optimizing dom size
- 10 Key techniques to avoid an excessive DOM size
- Use well-coded themes or page builders
- Don’t use page builders that generate bloated HTML
- Don’t copy/paste the text into the WYSIWYG editor
- Remove unnecessary items in the default WP theme
- Create multiple pages instead of one long page
- Don’t hide unwanted elements using display:none
- Improve page rendering with the content-visibility property
- Implement lazy load and infinite scroll
- Get experts’ help
- Wrapping up
What is DOM size and why does it matter?
Simply put, DOM (Document Object Model) refers to the structure of the objects that the browser generates each time it loads a page.
The DOM document model displays HTML as a tree diagram with branches and nodes. The structure is comparable to that of a tree because there is a principal object on which all secondary objects rely.
Why does the “Avoid an excessive DOM size” warning happen?
When the Document Object Model (DOM) size on a web page surpasses a specific threshold, the “Avoid an excessive DOM size” warning appears. The DOM is a tree-like structure representing the content and structure of a web page, with each HTML element expressed as a node in the tree.
The size of the DOM can grow as additional elements are added to a web page, which can harm the website’s performance.
When you hit an “Avoid an excessive DOM size” warning in your PageSpeed Insights (PSI) report, your DOM tree might have the following errors:
It contains over 1500 DOM nodes in total. That means there are more than 1500 HTML elements on your web page.
It has a maximum node depth of more than 32 nodes.
A parent node can have up to 60 child nodes. In other words, more than 60 children (list elements or table rows) are in a parent element.
In general, it is a good practice for web developers to keep the size of the DOM in check and optimize it for better performance.
The Impact of Excessive DOM Size
Slow down page loading time
Slower load times can be caused by a larger DOM, which can be a severe issue for web developers and website visitors.
The larger the DOM, the more resources need to be downloaded and processed by the browser, which can significantly slow down the page’s load time.
Increase the number of bytes transferred
It includes several invisible nodes for the user on the first load. This slows page loading speed and hurts network efficiency, leading to increased data costs and a poor user experience.
For example, a web page with a large number of HTML elements, such as a table with many rows and columns, will have a larger DOM size and require more bytes to be transferred than a more straightforward web page containing fewer HTML elements.
Because the browser must spend more time processing and rendering the content, a larger DOM might make a web page less responsive. This can negatively affect the user experience and keep users from entering your website.
Poor search engine rankings
A huge DOM can negatively impact a web page’s search engine ranking as it is more challenging for search engines (like Google) to crawl and index a web page.
Additionally, a larger DOM also increases the possibility of duplicate content on a web page, confusing search engines and reducing the page’s relevance.
Difficulty in maintaining code
Tools for optimizing dom size
Avoiding an excessive DOM size is essential to optimize your web page experience. We will explore some of the most used tools that can significantly help improve your website experience.
Google PageSpeed Insights
PageSpeed Insights is a free online tool from Google that can assist web developers in optimizing the performance of their web pages, including DOM size.
Google PageSpeed Insights can greatly help you with the following:
Resource prioritization: PSI can suggest how to prioritize the loading of resources on a web page, which can help reduce the size of the DOM
Server response time analysis: PSI also analyzes server response time, which can affect DOM size.
Mobile optimization: PSI recommends optimizing a web page for mobile devices since these devices often have slower connections and less processing power than desktop computers.
Lighthouse is a Google open-source tool that audits websites for performance, accessibility, and other best practices. Lighthouse can help optimize the size of the DOM and provide a range of performance measurements.
Lighthouse can help optimize your DOM size by:
Identifying render-blocking resources: By identifying and removing render-blocking resources delaying the loading and rendering of a web page, this tool helps developers reduce the size of the DOM and improve web performance.
Like the two tools above, GTmetrix is an online tool that can help developers optimize the performance of their web pages. In addition to DOM size analysis and resources optimization, GTmetrix can help you with the following:
Server response time analysis: it examines the server response time for a web page, which might affect the DOM size.
Being an online tool that can help web developers enhance the performance of their web pages, WebPageTest has some similarities to other DOM-size optimizing tools. And yet, this tool provides a waterfall analysis feature that can help identify resources that are causing delays or increasing the size of the DOM.
This tool allows developers to avoid an excessive DOM size and ensure their pages load quickly, ultimately enhancing website performance.
10 Key techniques to avoid an excessive DOM size
Use well-coded themes or page builders
Poorly coded themes and templates can have a detrimental impact on the performance of your website. They will bloat your site’s code, increase the size of your DOM, and influence your site’s speed and general performance.
For example, if you use a plugin that generates a huge number of DOM nodes (calender, slider, etc.), you need to replace it with a more optimized plugin.
But how to know if a plugin/theme is poorly coded? Here is the answer:
Check their last updates. If they are out-of-date, you should definitely want to skip them and find better ones.
Read the feedback. If there are any issues, someone has most certainly encountered them and provided feedback.
Don’t use page builders that generate bloated HTML
Page builders have become integral to website creation. They allow us to design web pages without any coding or programming knowledge. Unfortunately, these tools can occasionally yield bloated code with excessive DOM nodes.
Bloated HTML code can slow down the loading time of a web page, increase the file size, and contain unnecessary code. This can make it harder for web developers to maintain, debug, and make changes or updates to a web page.
Developers should use optimized code to improve website performance instead of page builders that generate bloated HTML code. However, some page builders are taking steps to tackle these well-known problems. Elementor, for example, has added DOM improvements to boost the performance of websites.
Don’t copy/paste the text into the WYSIWYG editor
Copying and pasting text into a What You See Is What You Get (WYSIWYG) editor can sometimes result in large, bloated HTML code. The reason is that most WYSIWYG editors fail at cleaning up copy-paste code, which creates additional DOM nodes.
The hidden formatting of copied and pasted text, even font styles or colors, increases DOM size. Sometimes, copying and pasting text into a WYSIWYG editor can result in inefficient HTML code. This might negatively impact the page’s performance and make it harder to optimize for search engines.
Remove unnecessary items in the default WP theme
In case you are using WordPress, removing certain elements (additional widgets or scripts) that come with your WordPress theme by default may be necessary.
You should check the WordPress theme’s setup to see if you can remove such items. If not, checking for the matching PHP code of these items may help you avoid an excessive DOM size.
Create multiple pages instead of one long page
You may have a single page displaying various types of content on your site, such as contact forms and blogs. This can also result in a big DOM tree.
Instead, try splitting large pages into multiple pages and link to them through the navigation bar. By doing this, you can reduce the number of DOM nodes and improve the loading speed of your website.
Don’t hide unwanted elements using display:none
Using display:none to hide unwanted elements on a web page can improve the page’s appearance and usability. However, this is not an effective way to reduce the size of the DOM.
In fact, even though the element is not visible on the page, it remains in the DOM. This can result in slower load times, especially if the page has too many hidden elements.
An alternative to using display:none is to use visibility:hidden instead or remove the element from the HTML markup. This technique can help avoid excessive DOM size and improve the page’s performance.
Improve page rendering with the content-visibility property
Typically, when a web browser loads a page, it renders all elements. On the other hand, the CSS content-visibility attribute instructs the browser to skip style, layout, and painting until the user scrolls down the page in a ‘just-in-time’ approach.
The content-visibility property allows developers to defer the rendering of non-critical elements until needed. This can help reduce the load time of a page and bounce rates.
Additionally, by improving the rendering of a web page with the content-visibility property, developers can provide a better user experience. This will ultimately increase engagement and conversion rates for the website.
Implement lazy load and infinite scroll
Lazy loading the selected parts of your website is an effective technique to optimize initial page rendering. You can also speed up page rendering by restricting the number of articles displayed on each blog page. 10 posts per page is a good choice.
Similar to lazy loading, infinite scrolling can help you speed up your page loading times. This is a good idea when users have to scroll through repeated elements, such as products or blogs.
Lazy loading and infinite scrolling help deliver a better user experience to visitors by providing a more seamless experience. It can also level up your rankings and drive more traffic to the site.
Get experts’ help
We know that it’s not easy to avoid an excessive DOM size, especially if you’re not a technical expert. That’s where Mageplaza comes into play!
Specializing in developing & optimizing worldwide e-commerce websites, Mageplaza is a great choice when you need to audit your website.
Here are the benefits that you will get:
Expert team: Our certified passionate experts work wholeheartedly to provide you with the best Magento site audit services.
In-depth reports & recommendations: We’ll provide reported issues along with recommended solutions when you need a Magento SEO audit, UI/UX audit, code audit, security audit and many more audit services.
Shortest time-to-market: As an experienced company, we have ready-made solutions for the Magento site audit service.
Transparent process: You can track relevant statuses and change the scope if necessary.
Free post-release support: Our support team will answer all relevant questions even after 2 months and help you get the most out of it.
Affordable cost: All of our Magento services are budget-friendly for SMBs. Contact us for a free consultation and quote.
Don’t hesitate to contact us today to learn more about our services and take your business to the next level!
An enormous DOM size not only degrades your website’s performance by slowing page load time but also affects the user experience. However, by following the right tools and techniques, web developers can optimize their web pages and avoid an excessive DOM size.
In this blog, we have discussed four tools and nine techniques that can help reduce the size of the DOM and improve the performance of a web page. By following these tools and techniques, web developers can create web pages optimized for performance, speed, and SEO.
& Maintenance Services
Make sure your store is not only in good shape but also thriving with a professional team yet at an affordable price.Get Started