Skip to content

Should dynamic import()ed script loading delay Window load events? #5824

@hiroshige-g

Description

@hiroshige-g

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    interopImplementations are not interoperable with each othertopic: script

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions