document.readyState test results

This document describes the results of the attached tests on various browsers. All tests were run on my Dell Latitude D620 running Windows XP SP2.

Executive summary: All of these results are quirky. The only consistent result is that document.readyState is "complete" during onLoad. (This is the "golden rule" of document.readyState.) Opera usually disagrees from all the other browsers, though it always follows the golden rule. In a curious twist, IE even disagrees with itself! (See the note below.)

NOTE: When running these tests in IE, there's a big difference between loading a test the first time and hitting refresh in the browser. (Refresh vs. shift-refresh doesn't appear to make a difference.) Where noted below, the tests were run twice, once with "iexplore.exe foo.html" and then again hitting shift-refresh in the browser once the previous test had finished.

Table of Contents

  1. simpletest.html
  2. parentFrame.html
  3. imagetest.html
  4. imagewritetest.html
  5. XSL test: testTransformable.xml

simpletest.html

Test Definition: This test log messages during an initial script tag, during "readystatechange", during "DOMContentLoaded" and during "load". It contains no images or other content that would delay the load event.

Result Summary: The only cross-browser constant in this test is "load: complete". The initial readyState is quirky, but it is always either "loading" or "interactive". "readyStateChange" normally fires before "load", but Opera is unique in firing "readyStateChange" after the ""load event. As we'll see later in imagetest.html, this allows Opera to avoid firing "readyStateChange" unnecessarily if activity during the load event causes document.readyState to revert back to "interactive".

parentframe.html

Test Definition: This test embeds simpletest.html in an iframe; additionally parentframe.html logs during its own initial script tag, during "readystatechange", during "DOMContentLoaded" and during "load".

Result Summary: These results look quirky, but they basically make sense based on the results from simpletest.html. The parentFrame starts before the subframe; the subframe starts, then finishes, then finally the parent frame finishes; the final line is "parentFrame load: complete". Opera is again the exception to this rule: Opera fires "readyStateChange" after "load", and fires parentFrame finishing events before subframe finishing events, which seems inappropriate to me.

imagetest.html

Test Definition: Like simpletest.html, this test logs messages during an initial script tag, during "readystatechange", during "DOMContentLoaded" and during "load". However, after logging a message during "load", this test adds a non-cached image to the DOM. It then logs a message immediately after adding the image ("addImage") and again during the image's "load" event.

Result Summary: Adding an image to the DOM does not cause document.readyState to decrease, except in the odd-man-out Opera. There, adding an image to the DOM reduces document.readyState to "interactive". Alarmingly, in Opera document.readyState never becomes "complete" again!

imagewritetest.html

Test Definition: Like simpletest.html, this test logs messages during an initial script tag, during "readystatechange", during "DOMContentLoaded" and during "load". However, after logging a message during "load", this test calls document.writeln to modify the document's content, adding a non-cached image. The test then associates a new load handler to the window ("write body load"), then logs a message ("addImage"), and logs another message during the image's "load" event.

Result Summary: document.write causes document.readyState to "regress" to a smaller value on all browsers; but every browser disagrees about what value that should be. (IE: loading, Safari: loaded, Opera: interactive, Minefield: loading.) document.write also seemed to delete my "readyStateChange" handler; I couldn't find a nice way to reattach it, but I can hardly see what we could hope to gain from it anyway.

XSL test: testTransformable.xml

Test Definition: This test is a bare-bones XML document with a stylesheet declaration "<?xml-stylesheet type="text/xsl" href="test.xsl"?>". The XSL file translates testTransformable.xml into an HTML file isomorphic with simpletest.html. The resulting HTML logs messages during an initial script tag, during "readystatechange", during "DOMContentLoaded" and during "load". It contains no images or other content that would delay the load event.

Result Summary: The results of this test are identical to the results of "simpletest.html" on every browser except Opera. Even there the difference is subtle; in simpletest.html Opera's readyState is "interactive" during "DOMContentLoaded", but here Opera's readyState is "complete" during "DOMContentLoaded". (That feels like an Opera bug to me.)