How to reduce the number of DOM elements on my website

A complex page means a lot of bytes to download and also means slow access to the DOM in Javascript.

This denotes the difference if you repeat through 500 or 5000 DOM elements on the page when you want to add an event handler for example.

A high number of DOM elements can be a symptom that there is something that needs to be improved with the markup of the page without the need to affect or remove the content. Are you using nested tables for design purposes? Are you creating "

" just to fix layout problems? Perhaps there is a better way to make your markup more semantically.

This is an opportunity to start over and think about markup. For example, the use of

only makes semantic sense, and not because it creates a new line.

Finding the number of DOM elements is easy, just type in the Firebug console:

document.getElementsByTagName ('*'). length

And how many DOM elements are considered too many? Check out other similar pages that have good bookmarking.

Date update on 2020-11-13. Date published on 2020-11-13. Category: Computer class Author: Oscar olg Fuente: tecnologia