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

  • SEARCH
  • Home
  • 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 8855689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:11:34+00:00 2026-06-14T14:11:34+00:00

I am trying to create a loading bar during a very intensive period of

  • 0

I am trying to create a loading bar during a very intensive period of JavaScript where some pretty heavy 3d arrays are built and filled. This loading bar needs to remain empty until the user clicks a button.

The freezing occurs whether or not I’m using -webkit-transition (This app can be chrome exclusive, cross browser is not necessary in my case).

Seeking simplicity I’ve built my bar like this…

<div id="loader">
    <div id="thumb">
    </div>
</div>

… and then sought to increment that bar at various stages of my main for loop:

for(i = 0; i < 5 ; i++){
    document.getElementById('thumb').style.width = i*25 + '%';
    //More Code
}

Problem is that everything freezes until the JavaScript finishes.
I found a similar question on Stack Overflow, Using CSS animation while javascript computes, and in the comments found and considered and/or tried the following:

  • Web Workers

    Don’t think it’ll work since my script is filling an array with objects and constructors containing functions which according to this site isn’t going to work

  • jQuery

    Not an option, I can’t use external libraries in my app – in any case, importing a whole library just for a loading bar seems kind of like overkill…

  • Keyframes

    This was promising and I tried it, but in the end it freezes also, so no joy

  • timeOut()s

    Thought about this, but since the point of the loading bar is to reduce frustration, increasing the waiting time seems counter-productive

I’d be happy to have any incrementation of the bar at this stage, even if it’s not smooth! I’m pretty sure this is a problem that has struck more than just me – maybe someone has an interesting solution?

P.S.: I’m posting this as a new question rather than adding to the referenced question since I’m specifically seeking help with JavaScript (not jQuery) and would prefer if I could get it using a transition (!=animation) on the width.

  • 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-14T14:11:35+00:00Added an answer on June 14, 2026 at 2:11 pm

    Some people already mentioned that you should use timeouts. That’s the appropriate approach, bc it’ll give the browser time to “breathe” and render your progress bar mid-task.

    You have to split your code up to work asynchronously. Say you currently have something like this:

    function doAllTheWork() {
      for(var i = 0; i < reallyBigNumberOfIterations; i++) {
        processorIntensiveTask(i);
      }
    }
    

    Then you need to turn it into something like this:

    var i = 0;
    function doSomeWork() {
      var startTime = Date.now();
      while(i < reallyBigNumberOfIterations && (Date.now() - startTime) < 30) {
        processorIntensiveTask(i);
        i++;
      }
    
      if(i < reallyBigNumberOfIterations) {
        // Here you update the progress bar
        incrementBar(i / reallyBigNumberOfIterations);
    
        // Schedule a timeout to continue working on the heavy task
        setTimeout(doSomeWork, 50);
      }
      else {
        taskFinished();
      }
    }
    
    function incrementBar(fraction) {
      console.log(Math.round(fraction * 100) + ' percent done');
    }
    
    function taskFinished() { console.log('Done!'); }
    
    doSomeWork();
    

    Note the expression (Date.now() - startTime) < 30. That means the loop will get as much done as it can in the span of 30 milliseconds. You can make this number bigger, but anything over 100ms (essentially 10 frames-per-second) is going to start feeling sluggish from the user’s point of view.

    It may be true that the overall task is going to take somewhat longer using this approach as opposed to the synchronous version. However, from the user’s experience, having an indication that something is happening is better than waiting indefinitely while nothing seems to be happening – even if the latter wait time is shorter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to create a very simple app where at loading the main
I'm trying to create some cascading drop downs. I have my States loading via
I am trying to create a loading progress bar for my function: private string
I'm trying to create a custom loading/throbber icon for my app. I have an
I am trying to create a simple Twitter client with lazy loading of Twitter
I'm loading a dynamic application (which takes 20-30 seconds), and I'm trying to create
I am trying to create a custom loading dialog that displays an animated loading
I am trying to create a loading function that build a basic DOM with
I am trying to create a loading image when user clicks submit button. For
I'm trying to create a sandboxed AppDomain for loading extensions/plugins. I have a MarshalByRefObject

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.