Skip to content

Commit

Permalink
Handle inline script when s.js is inlined
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien Maillard committed Nov 2, 2021
1 parent 98609db commit 737faab
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/features/script-load.js
Original file line number Diff line number Diff line change
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;
lastAutoImportDeps = deps;
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 737faab

Please sign in to comment.