I really like using libraries as Vue
and AngularJs
and my favorite implementation was Infinite Scroll (or demand-driven loading). I mean, I initially load 15 records via ajax. If the user scrolls the page, loads another 15, and so on until the logs are finished, and assembling the elements in the DOM accordingly.
I wonder if this operation can cause some performance problem regarding memory or even navigation (causing crashes, for example).
I do not want to get into discussions about the Angular Watcher, ng-repeat, and the like, but rather know specifically about the DOM.
Have many elements in the DOM affect performance?
For example, if I do an infinite scroll on my page, and it generates about 10,000 divs, could this impact my page performance?
Is there any recommendation on this?
Example:
var listElm = document.querySelector('#infinite-list');
var nextItem = 1;
var loadMore = function() {
for (var i = 0; i < 100; i++) {
var item = document.createElement('li');
item.innerText = 'Item ' + nextItem++;
listElm.appendChild(item);
}
}
listElm.addEventListener('scroll', function() {
if (listElm.scrollTop + listElm.clientHeight >= listElm.scrollHeight) {
loadMore();
}
});
loadMore();
#infinite-list {
/* We need to limit the height and show a scrollbar */
width: 200px;
height: 300px;
overflow: auto;
/* Optional, only to check that it works with margin/padding */
margin: 30px;
padding: 20px;
border: 10px solid black;
}
/* Optional eye candy below: */
li {
padding: 10px;
list-style-type: none;
}
li:hover {
background: #ccc;
}
<ul id='infinite-list'>
</ul>