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

153
Visualizações
How to make multiple image source assignments not make the page stuck?

I need to dynamically create a list of a couple thousand elements. Each list item contains an image of about half a Kb and some text.

The problem is that the assignment of all image sources to my list items, using the .src of my <img> elements, is taking a long time and making the page completely stuck for some seconds.

Is there a way that I could do this maybe asynchronously or more efficiently so that the page doesn't get stuck during the list generation?

Here's a simplified version of my code. If I remove the line with .src assignment, the code runs instantaneously.

// About a couple thousand elements
const item_data = [ 
    {text: "text1", image: "img/image1.png"}, 
    {text: "text2", image: "img/image2.png"},
    ... ];

const my_list = document.createElement("ul");

for (const item of item_data) {

    const list_item = document.createElement("li");

    const list_item_text = document.createElement("p");
    list_item_text.innerText = item.text;

    const list_item_image = document.createElement("img");
    list_item_image.src = item.image;

    list_item.appendChild(list_item_text);
    list_item.appendChild(list_item_image);

    my_list.appendChild(list_item);
}

document.body.appendChild(my_list);
about 4 years ago · Juan Pablo Isaza
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