I write a test for continuous batch dom update in the code below:
const container = document.querySelector('#container');
const button = document.querySelector('button');
function fulfill(text) {
container.innerHTML = '';
for (let i = 0; i < 10000 * 3; i++) {
const label = document.createElement('div');
label.innerHTML = text;
container.appendChild(label);
}
}
button.onclick = function () {
fulfill("Hello");
fulfill("World");
}
<button>Click</button>
<div id="container"></div>
If the fulfill
function execute sequentially twice, the page should show Hello
first, and then show World
. But it seems only show World
eventually
So I guess the browser seems optmize continuous batch dom update natively? But I can't find any documents or references about it. Which keywords should use to google it?