Browsers will usually not update images while JavaScript code is running. If you need a counter to continue the animation while filling in the DOM, the population function will have to give the browser control several times per second to update the image, usually by setting a timeout (no delay or a very short delay), which returns to the population process and then comes back.
Unfortunately, this usually makes your population function a lot more complicated, as you need to keep track of how far you have in the population process in variables, rather than relying on loops and conditional structures to remember where you are are. In addition, it will run a little slower, depending on how you fill out the page structures, and if there is a click or other events that your application may receive halfway through the population, you may encounter unpleasant race conditions.
IMO, it would probably be better to stop the counter and then update the DOM. You still get a pause, but without spinning the spinner all the way, it will not be so noticeable. To enable the browser to update the counter after ajaxStop changed its src , use the zero-delay delay function in your AJAX callback function so that when the browser finishes, it will be able to display the changed counter before going into a long demographic code.
Making the population move faster is certainly worth it if the topic is slightly different. (Adding multiple DOM elements one after the other is essentially slower, since each operation has to spend more time flipping through list operations. Quickly adding many DOM elements immediately through DocumentFragment is quick, but getting all of these DOM elements in a fragment in the first place can there is no analysis of all innerHTML immediately, but generating HTML without holes in security is a nuisance, serializing and re-sorting through innerHTML+= slower and horrible IE / HTML5 insertAdjacentHTML fast but requires backups for many browsers: ideally fast range manipulation, returning to a slow node -by-node DOM calls for browsers without a range.Don't expect the jQuery append do this for you as slow as a node -by-node DOM operation, because that is exactly what he is doing.)
source share