Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda