Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support runtime script loading w/ load statuses #23

Open
logannc opened this issue Jun 29, 2018 · 0 comments
Open

Support runtime script loading w/ load statuses #23

logannc opened this issue Jun 29, 2018 · 0 comments

Comments

@logannc
Copy link
Contributor

logannc commented Jun 29, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant