Here is a piece of code from the jQuery source (bit.ly/jqsource):
// The DOM ready check for Internet Explorer
function doScrollCheck() {
if ( jQuery.isReady ) {
return;
}
try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch(e) {
setTimeout( doScrollCheck, 1 );
return;
}
// and execute any waiting functions
jQuery.ready();
}
It is a hack to detect when the DOM is ready for IE. While theoretically this seems very beautiful, I'm a little concerned about setTimeout( doScrollCheck, 1 );
, which means that the function doScrollCheck()
is called 1000 times per sec before the DOM is ready.
Should I expect this to be a huge performance drain?
The setTimeout
function is almost never called at exactly the requested time. The browser is free to do a +/- on the time by a few milliseconds, at the least, and if there is any other intensive work going on then it can be delayed by seconds or more. As others have already mentioned, the browser also implements a minimum timeout time. This 1 millisecond simply tells the browser 'as soon as you're done doing whatever you're doing, let me know so I can do something'. It also yields execution from the Javascript so that the browser can return to doing whatever it will do next.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With