Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!