Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
How many repaints of the DOM will appending children in a for loop cause?

How many repaints of the DOM will appending children in a for loop cause?

I was under the impression this would cause 200. 1 for each time an element is appended, and 1 every time its textContent is updated.

But, in Jake Archibald's talk at JSConf, he seems to mention that browsers will batch this together.

for (let i = 0; i < 100; i++){ 
  const div = document.createElement('div');
  document.body.appendChild(div);
  div.textContent = 'Hello';
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Only once; see Erin Zimmer's continuation on the rendering pipeline https://youtu.be/u1kqx6AenYw

Also, you may test it with something like:

//document.body.innerHTML = '';
for (let i = 0; i < 100; i++){ 
  const div = document.createElement('div');
  document.body.appendChild(div);
  div.textContent = 'Hello';
  let x = 0;
  for(let j = 0; j < 1e7; j++){
     x += Math.sin(Math.random())
  }
}```
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda