Skip to content

Commit

Permalink
Sometimes on cache hits, IE will execute the script before it has eve…
Browse files Browse the repository at this point in the history
…n added it to the DOM, remember what script is currently being added, and if it gets added during the appendChild operation (and there is nothing in interactive state), use that script.
  • Loading branch information
kriszyp committed Sep 17, 2010
1 parent a9eb9fc commit 14ad005
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/browsertests/scriptloadinteractive/index.html
Expand Up @@ -16,6 +16,7 @@
useInteractive = false,
loadedScripts = [],
callCount = 0,
currentlyAddingScript,
waitingFunc, loadUrls,
urls = [
"one.js",
Expand Down Expand Up @@ -75,7 +76,6 @@
}
}
}

function attachScript(url, name, useDocWrite) {
if (noCache) {
url += "?stamp=" + (new Date()).getTime();
Expand All @@ -94,8 +94,10 @@
useInteractive = true;
node.attachEvent("onreadystatechange", onTestScriptLoad);
}
currentlyAddingScript = node;

document.getElementsByTagName("head")[0].appendChild(node);
currentlyAddingScript = null;
}

loadUrls = function () {
Expand All @@ -105,10 +107,12 @@
};

function def(func) {
var scripts, script, i;
var scripts, i, script = currentlyAddingScript;
if (useInteractive) {
scripts = document.getElementsByTagName('script');
var states = [];
for (i = scripts.length - 1; i > -1; i--) {
states.push(i + scripts[i].readyState + scripts[i].src);
//log('script with name ' + scripts[i].getAttribute('data-name') + ' has readyState = ' + scripts[i].readyState + ' for func: ' + func);
if (scripts[i].readyState === 'interactive') {
script = scripts[i];
Expand All @@ -117,6 +121,7 @@
}
if (!script) {
log("ERROR: No matching script interactive for " + func);
log("script readyStates are: " + states);
}
//log('calling finishScript for interactive dat-name: ' + script.getAttribute('data-name'));
finishScript(script, func);
Expand Down

0 comments on commit 14ad005

Please sign in to comment.