JavaScript execution and rendering
In most browsers, rendering and JavaScript use a single event queue. This means that JavaScript is not rendering while running.
Check out the demo below. When you click run, the browser may stop for some time because it changes div.style.backgroundColor from
A00000 to #FFFFFF.
In most browsers, you see nothing until the script ends, or until the browser pauses it with a message in which "w370" has been running for a long time.
The exception is Opera.
In Opera, you may notice that the div is redrawing. Not every change causes a redraw, possibly due to Operaβs internal planning. This is because event queues for rendering and JavaScript are different in this browser.
In other browsers, redrawing is delayed until JavaScript finishes.
Again, the implementation may be different, but usually the nodes are marked as "dirty" (they want to be recounted and redrawn), and repaint is queued. Or the browser can simply search for dirty nodes after each script and process them.
Immediate overflow The browser has many optimizations to speed up rendering and painting. As a rule, he tries to postpone them until the script is completed, but for some actions, node reloads are required immediately.
For example: elem.innerHTML = "new content" (elem.offsetHeight) // <- rerenders elem to get offsetHeight. In the above example, the browser has to relay to get the height. But it does not need to repaint ale on the screen.
Sometimes other dependent nodes may be involved in the calculations. This process is called reflow and can consume a lot of resources if the script calls it often.
Of course, much more talk about rendering. It will be covered in a separate article [todo].