Example:
<body onload="console.log('Window load event')">
<script>
// Executed after 1 sec.
setTimeout(() => console.log('loading'), 1000);
// Resolved after 2 sec loading
import('./slow-script-taking-2sec-to-load.js').then(() => console.log('imported'));
</script>
</body>
WPT: web-platform-tests/wpt#25005
- Spec:
Window load event/loading/imported.
- Dynamic imports don't seem to
#delay-the-load-event. Therefore, Window load event would be fired even while dynamic imports are loading.
- Chromium:
loading/Window load event/imported.
- The Window load event is delayed until finishing loading dynamically imported scripts, but not until the
then callback of import() promise. Just after the load finish, a Window load event is fired and then the then callback of import() promise.
- Firefox and Safari:
loading/imported/Window load event.
- The Window load event seems delayed until the
then callback of import() promise.
Given that all browsers delay the load event, perhaps it's better to make the spec also delay the load event, e.g. by changing https://html.spec.whatwg.org/multipage/webappapis.html#hostimportmoduledynamically(referencingscriptormodule,-specifier,-promisecapability).
Example:
WPT: web-platform-tests/wpt#25005
Window load event/loading/imported.#delay-the-load-event. Therefore, Window load event would be fired even while dynamic imports are loading.loading/Window load event/imported.thencallback ofimport()promise. Just after the load finish, a Window load event is fired and then thethencallback ofimport()promise.loading/imported/Window load event.thencallback ofimport()promise.Given that all browsers delay the load event, perhaps it's better to make the spec also delay the load event, e.g. by changing https://html.spec.whatwg.org/multipage/webappapis.html#hostimportmoduledynamically(referencingscriptormodule,-specifier,-promisecapability).