Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:32:12+00:00 2026-06-01T04:32:12+00:00

I am coding a script in which the user selects a range of data,

  • 0

I am coding a script in which the user selects a range of data, and then I fetch a bunch of images (over 150) from the server and then I loop trough them to make something like a movie. What I want to know is the most efficient way to load prevent lag when moving trough the images.

Currently I am fetching the images from the server using Ajax and store them in a array of Image objects on the JavaScript. In the HTML I have a div tag in which I wish to put the images. After I finished creating all the Image object (and setting their proper src) in the array, I do the following:

imgElem = document.createElement('img');
document.getElementById('loopLocation').appendChild(imgElem);
imgElem.src = images[0].src;

After this I just make that last call but changing the loop index. I do that every 400ms. The loop works, but sometimes it lags and it freezes on an image for longer that it is supposed to be. I want to know if I am able to improve this anymore from the client side or I just need a server that responds faster.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:32:14+00:00Added an answer on June 1, 2026 at 4:32 am

    you might wanna consider spriting which is putting all images into one big image. with this, you only need to load one big image, and then just reposition for every scene.

    or, you might also want to pre-load those 150 images, before actually using them. you can use JS array to store Image objects and then loop through that array to get your images.

    var images = [];
    var expectLoaded = 150;
    
    for(var i = 0; i<expectLoaded;i++){
        (function(i){
    
            //new image object
            var img = new Image();
    
            //onload hander
            img.onload = function(){
    
                //after load, push it into the array
                images.push[img];
    
                //and check if the all has loaded
                if(images.length === expectLoaded){
                    //preload done
                }
            }
    
            //start loading this image
            img.src = //path to image[i];
    
        },(i));
    }
    

    loops block the UI thread. JS is single-threaded, meaning code gets executed in a linear fashion, one after the other. anything that comes after that loop statement will wait until the loop finishes. if that loop takes long… grab some coffee. plus, since you are manipulating the DOM, you don’t see the changes since the UI thread is blocked.

    but there are ways to bypass this, and one of them is using timeouts to delay and queue the code for later execution, when JS is not busy.

    function animate(frameNo){
    
        //animate frame[frameNo];
    
        if(frameNo < total_frames){    //make the UI breate in between frames
            setTimeout(function(){   //so that changes reflect on the screen
                animate(++frameNo);  //then animate next frame
            },200);                  
        }
    }
    
    //start
    animate(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently coding a simple search script in PHP that requires three variables from
I have made this batch script which will allow the user to enter a
I have a Django view, which receives part of its data from an external
I have an app which amounts to a Python script, running on the user's
I'm coding a Python script which is using the application pdftk a few times
So I'm working on app that involves leveraging user profile data from FB. But
i have a form which user enters some data, could be checkboxes, radio buttons,
I have a batch script that prompts a user for some input then outputs
I came across a confusing fact during coding a script. How can i find
I'm looking for a script/tool that can be customized to check and enforce coding/naming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.