In some cases (read older SharePoint) we load the Aurelia bundles by first injecting script to the page. There is no other way to get script on the page, but to register a short script that injects the SCRIPT-tag. The first line of code in the bundle adds a DIV-tag with an ‘aurelia-app’ attribute.
We know that the injection of our script is always inserted after the complete BODY-element is loaded. So in an Aurelia perspective the DOM is loaded. The problem is that there is a lot of script injections going on that is out of our control. Somehow the script injections delays the ‘DOMContentLoaded’ event in best case for a few seconds and in worst case for more than 30 seconds after a time-out happens.
The user is not happy to wait for 30s before the Aurelia UI is turned on. Aurelia is super fast to load as soon as the ‘DOMContentLoaded’ event is triggered. The problem in this case is that we are sort of waiting for nothing.
Here is the code from aurelia-bootstrap.js that checks if the DOM is loaded and otherwise registers an event.
function ready() {
if (!host.document || host.document.readyState === 'complete') {
return Promise.resolve();
}
return new Promise(resolve => {
host.document.addEventListener('DOMContentLoaded', completed);
host.addEventListener('load', completed);
function completed() {
host.document.removeEventListener('DOMContentLoaded', completed);
host.removeEventListener('load', completed);
resolve();
}
});
}
If I change the first line to something silly like
if (true) {
return Promise.resolve();
}
Aurelia load fast like a tiger.
It would be sweet if we could skip the DOM-ready check by configuration.
I understand that I can create my own fork of this, but I am interested to hear if there is anyone else that have the same or similar issue.