Is it not good to remove elements from HTML that are not visible?

I did a slide show using jQuery, which at the moment is just using append()to add <img>to the container that was previously defined. The slide show automatically rotates, returning to the beginning of the final slide and continuing indefinitely.

At the moment, I am not deleting the previous image in the container at all. I did not notice anything change in terms of performance or filling up my memory - the behavior that I'm used to in Flash, if I continued to add elements without deleting the old ones.

Do old images need to be deleted or will they never cause performance problems?

+5
source share
4 answers

Some of them may be browser dependent, but on the whole I would say that yes, it is really “bad” not to clear old elements. Regardless of whether the element is visible, it still adds node to the DOM structure, and you cannot add to the DOM indefinitely.

If perhaps the browser does not use some kind of intelligent cropping algorithm that collapses the unused / invisible parts of the DOM, but I have never heard that this is done in practice.

+2
source

, , , , , , , , , , . , . , .

+2

$(div).innerHTML='' , div?

0

. , . , . -, , . , , . , .

, .

0

All Articles