This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The Document.readyState property describes the loading state of the document. When the value of this property changes, a readystatechange event fires on the document object.
The readyState of a document can be one of following:
loadingThe document is still loading (that is, the HTML parser is still working).
interactiveThe document has been parsed but sub-resources such as deferred and module scripts, images, stylesheets, and frames are still loading. Once in this state, and the deferred and module scripts have executed, the DOMContentLoaded event fires.
completeThe document and all sub-resources have finished loading. The state indicates that the load event is about to fire.
switch (document.readyState) {
case "loading":
// The document is loading.
break;
case "interactive": {
// The document has finished loading and we can access DOM elements.
// Sub-resources such as scripts, images, stylesheets and frames are still loading.
const span = document.createElement("span");
span.textContent = "A <span> element.";
document.body.appendChild(span);
break;
}
case "complete":
// The page is fully loaded.
console.log(
`The first CSS rule is: ${document.styleSheets[0].cssRules[0].cssText}`,
);
break;
}
// Alternative to DOMContentLoaded event
document.onreadystatechange = () => {
if (document.readyState === "interactive") {
initApplication();
}
};
// Alternative to load event
document.onreadystatechange = () => {
if (document.readyState === "complete") {
initApplication();
}
};
document.addEventListener("readystatechange", (event) => {
if (event.target.readyState === "interactive") {
initLoader();
} else if (event.target.readyState === "complete") {
initApp();
}
});
| Specification |
|---|
| HTML> # current-document-readiness> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
readyState |
1 | 12 | 3.6 | 11Opera Presto fires 'complete' late after the 'load' event (in an incorrect order as per HTML5 standard specification). |
1 | 18 | 4 | 11Opera Presto fires 'complete' late after the 'load' event (in an incorrect order as per HTML5 standard specification). |
1 | 1.0 | 4.4 | 1 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState