Which technique below is better from a user experience?
In both examples, assume that thumbContainer
is set to the return value of document.getElementById('thumbContainer')
, and new Thumbnail(thumb).toXMLString()
returns a string with XHTML markup in it.
A) Simply +=
with thumbContainer.innerHTML
:
for (thumb in thumbnails) {
thumbContainer.innerHTML += new Thumbnail(thumb).toXMLString();
}
B) Or converting new Thumbnail(thumb).toXMLString()
to DOM elements and using appendChild
?
for (thumb in thumbnails) {
var shell = document.createElement('div');
shell.innerHTML = new Thumbnail(thumb).toXMLString();
for (i = 0; i < shell.childElementCount; i++) {
thumbContainer.appendChild(shell.children[i]);
}
}
I've used both and get complaints from Firefox that I've got a long-running script, and do I want to stop it?
Which loop is less-tight, that will allow the UI to update as new elements are added to the DOM?