I have got a vanilla Javascript that sets an img's src attribute to a data-uri.
In the function assigned to the onload
event, I try to show the progress of some preparations on the page that might take a while (multiple canvas elements are generated and a few settings are set).
This is the function, that should render a progress bar:
let progress = document.querySelector('.progress');
function showProgress(message, percent) {
console.log(message + ' (' + (percent * 100).toFixed(0) + '%)');
progress.querySelector('.progress--message').innerHTML = message;
progress.querySelector('.progress--bar-container--bar').style.width = (percent * 100).toFixed(0) + '%';
}
The code is run like this:
img.onload = function() {
showProgress('Preparing image...' .1);
// Some preparations...
showProgress('Preparing tools...', .2);
// etc...
showProgress('Done...', 1);
}
The console logging works as intended, but the rendering of the DOM elements stops until the end of the function and displays the "done" state after everything is ready.
Is there any render-blocking in the onload
event handling and can it be circumvented? Or am I missing something? The code itself does not have any effect on the outcome. Even the first line in the function does have this strange behaviour.