Stumbling upon a Javascript DOM Elements Counter here and here (courtesy of lingtalfi) I want to speed up my website. Apparently the number of, the length of and the depth of DOM elements seems to have an impact on speed. I want to count the DOM overhead and show it in the HTML without a need for a keypress. This could be done 5 seconds after the page has loaded to not interfere with the speed of the website.
Method 1: Alert Popup Box
<a href="
javascript: (function()
{alert(document.getElementsByTagName('*').length);
}());
">Count DOM nodes of a page
</a>
Method 2: Just Write in HTML
<script>
(function() {
document.write(document.getElementsByTagName('*').length);
}());
</script>
On my site the first method popups 814, while the second method writes 142. Quite a difference!
My question is: Is there a way to (delay and) output the correct number of DOM elements just in HTML without the need to click on a popup to count the DOM elements?
(function () {document.write(document.getElementsByTagName('*').length); }());
body {
font-size: 5em;
font-family: "Arial";
}