Skip to content

Commit

Permalink
Handle inline script + systemjs inlined
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien Maillard committed Nov 2, 2021
1 parent 4da6ac7 commit debe25e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/features/script-load.js
Expand Up @@ -30,24 +30,30 @@ systemJSPrototype.createScript = function (url) {
};

// Auto imports -> script tags can be inlined directly for load phase
var lastAutoImportUrl, lastAutoImportDeps, lastAutoImportTimeout;
var lastAutoImportDeps, lastAutoImportTimeout;
var autoImportCandidates = {};
var systemRegister = systemJSPrototype.register;
var inlineScriptCount = 0
systemJSPrototype.register = function (deps, declare) {
if (hasDocument && document.readyState === 'loading' && typeof deps !== 'string') {
var scripts = document.querySelectorAll('script[src]');
var lastScript = scripts[scripts.length - 1];
var lastAutoImportUrl;
if (lastScript) {
lastAutoImportUrl = lastScript.src;
lastAutoImportDeps = deps;
// if this is already a System load, then the instantiate has already begun
// so this re-import has no consequence
var loader = this;
lastAutoImportTimeout = setTimeout(function () {
autoImportCandidates[lastScript.src] = [deps, declare];
loader.import(lastScript.src);
});
}
else {
inlineScriptCount++
lastAutoImportUrl = document.location.href + "__inline_script__" + inlineScriptCount;
}
// if this is already a System load, then the instantiate has already begun
// so this re-import has no consequence
var loader = this;
lastAutoImportTimeout = setTimeout(function () {
autoImportCandidates[lastAutoImportUrl] = [deps, declare];
loader.import(lastAutoImportUrl);
});
}
else {
lastAutoImportDeps = undefined;
Expand Down

0 comments on commit debe25e

Please sign in to comment.