switch (document.readyState) {case "loading":// The document is still loading.break;case "interactive":// The document has finished loading. We can now access the DOM elements.var span = document.createElement("span");span.textContent = "A <span> element.";document.body.appendChild(span);break;case "complete":// The page is fully loaded.console.log("Page is loaded completely");break;}
// Place in header (do not use async or defer)document.addEventListener('readystatechange', event => {switch (document.readyState) {case "loading":console.log("document.readyState: ", document.readyState,`- The document is still loading.`);break;case "interactive":console.log("document.readyState: ", document.readyState,`- The document has finished loading DOM. `,`- "DOMContentLoaded" event`);break;case "complete":console.log("document.readyState: ", document.readyState,`- The page DOM with Sub-resources are now fully loaded. `,`- "load" event`);break;}});