Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad to not remove elements from HTML that aren't visible?

I've made a slideshow using JQuery which at the moment just uses append() to add an <img> to a container that was previously defined. The slideshow automatically rotates through, returning back the the start after the final slide and continuing infinitely.

At the moment, I don't remove the previous image in the container at all. I haven't noticed anything change in terms of performance or my memory filling up - a behaviour that I'm used to in Flash if I were to continue adding elements without removing old ones.

Is it necessary to remove the old images, or are these never going to cause performance issues?

like image 775
Marty Avatar asked Oct 11 '22 00:10

Marty


1 Answers

Some of this might be browser-dependent, but in general I would say that yes it is indeed "bad" not to clean up your old elements. Whether or not an element is visible, it is still adding a node to the structure of the DOM, and you cannot add to the DOM infinitely.

Unless perhaps the browser implements some sort of intelligent pruning algorithm that swaps out unused/non-visible portions of the DOM, but I've never heard of such a thing being done in practice.

like image 134
aroth Avatar answered Oct 16 '22 14:10

aroth