diff --git a/demos/ready.js b/demos/ready.js index 8da412411bb..da9c49cad18 100644 --- a/demos/ready.js +++ b/demos/ready.js @@ -27,6 +27,7 @@ window.demoReady = (function(root) { var POLL_MAX_WAIT_MS = 60 * 1000; var isReadyCached = false; + var isDomLoaded = false; var handlers = []; var testDom = null; var startTimeMs = null; @@ -38,7 +39,7 @@ window.demoReady = (function(root) { } ensureDetectionDom(); isReadyCached = getComputedStyle(testDom).position === 'relative' && - (Boolean(window.mdc) || !root.querySelector('script[src*="material-components-web.js"]')); + (Boolean(window.mdc) || (isDomLoaded && !root.querySelector('script[src*="material-components-web.js"]'))); return isReadyCached; } @@ -94,6 +95,10 @@ window.demoReady = (function(root) { handlers.length = 0; } + root.addEventListener('DOMContentLoaded', function() { + isDomLoaded = true; + }); + return function addHandler(handler) { if (isReady()) { handler(root);