Skip to content

Commit

Permalink
fix(jqLite): revert the #ready() optimization until jQuery does the same
Browse files Browse the repository at this point in the history
The change unfortunatelly makes us incompatible with jQuery which always falls back to onLoad.

Not falling back to onLoad is a possible breaking change because if Angular was added to the document during DOMContentLoaded
document.readyState at this point is 'interactive' which we'd need to add to our check, but more importantly if more scripts
are added during DOMContentLoaded these won't be loaded before we bootstrap, which can cause angular modules not to be found
during bootstrap.

This load ordering issues is really just a cornercase that should be handled via manual bootstrap, but until jQuery has the same
behavior we shouldn't do something else.
  • Loading branch information
IgorMinar committed Aug 19, 2014
1 parent bf1a57a commit 1bdca93
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,24 @@ function jqLiteRemove(element, keepData) {
//////////////////////////////////////////
var JQLitePrototype = JQLite.prototype = {
ready: function(fn) {
// check if document already is loaded
var fired = false;

function trigger() {
if (fired) return;
fired = true;
fn();
}

// check if document is already loaded
if (document.readyState === 'complete'){
setTimeout(fn);
setTimeout(trigger);
} else {
this.on('DOMContentLoaded', fn);
this.on('DOMContentLoaded', trigger); // works for modern browsers and IE9
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
// jshint -W064
JQLite(window).on('load', trigger); // fallback to window.onload for others
// jshint +W064
this.on('DOMContentLoaded', trigger);
}
},
toString: function() {
Expand Down

0 comments on commit 1bdca93

Please sign in to comment.