jQuery: Enforce order of execution of document.ready() calls

document.ready() callbacks are called in the order they were registered. If you register your testing callback first, it will be called first.

Also if your testing code does not actually need to manipulate the DOM, then you may be able to run it as the code is parsed and not wait until the DOM is ready which would run before the other document.ready() callbacks get called. Or, perhaps you could run part of your testing code immediately and defer only the part that uses the DOM until document.ready().

Another idea is (for testing purposes only) you could run with a slightly modified version of jQuery that added a flag to document.ready() that when passed and set to true indicated to call that function first or you could add a new method document.readyFirst() that would call your function first. This would involve minor changes to the document.ready() processing code in jQuery.

Leave a Comment