Skip to content

Support runtime script loading w/ load statuses #23

@logannc

Description

@logannc

It is valuable to know whether a particular script loaded or failed when root causing client side errors, though it is not always possible to determine which set of scripts is loaded after the fact. With runtime based loading, you can attach a load event handler which registers that the script successfully loaded, so you can detect important scripts absences when looking at error events.

The runtime loading would be similar to:

var scripts = [...]; // deps, essentially
window.loadedScripts = [ ];
var myself = ... get own script tag ...;
var previous = myself;
for (var i = 0; i < scripts.length; i++) {
    var tag = document.createElement('script');
    tag.addEventListener('load', function (e) { window.loadedScripts.push(e.target.src); });
    tag.src = scripts[i];
    previous.parentNode.insertBefore(tag, previous.nextSibling);
    previous = tag;
}

which would replace the current insert of many manual <script></script> tags. Load speed should be negligibly affected since the browser theoretically blocks DOM parsing on each script tag anyway (we might lose a few ms from not being able to benefit from lookahead - but once this script is done lookahead will resume during the download/execution of the first imported script).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions