It's not clear for me whether browser initiates reflow during script run time, or after execution. So basically, If I have a loop (100 iteration), that inserts an element into the DOM, the browser stops the script execution, recalculates the layout with the inserted element, repaints in every step? And then the next step comes? Or it inserts the 100 element without stopping, and then reflow comes?
To translate it to code, are there any performance difference beetween the two code?
for(let i = 0; i < 100; i++){
$('body').append('<div>SOmething....</div>')
}
OR is it better?
let a = $('<div></div>');
for(let i = 0; i < 100; i++){
$(a).append('<div>SOmething....</div>')
}
$('body').append(a)
Or maybe is there even a better and more efficient solution for inserting a huge amount of elements (10000 or even more) into the DOM the doesn't slow down the browser that much?