3 ms·
I was under the impression that "DOM ready" did not wait for CSS, but that "load" did. In fact, i was also under the impression that CSS (loaded in the <head> a
by untog 14y ago
I was under the impression that "DOM ready" did not wait for CSS, but that "load" did. In fact, i was also under the impression that CSS (loaded in the <head> at least) blocked any further processing until it's downloaded. Am I wrong?
- eli 14y agoJS called from the head (without "async") blocks all further progress, but I don't think CSS necesarily does. (Though of course the page can't actually render to the screen without all the CSS.) SO seems to back that view up: http://stackoverflow.com/questions/4026183/as-javascript-in-head-blocks-html-rendering-is-it-not-the-case-with-css-also http://stackoverflow.com/questions/4026183/as-javascript-in-... YMMV in older versions of IE. I think everything blocks with them. I'm not sure about ready vs load, but that would make sense.
- kevincennis 14y agoWell, "DOM ready" isn't really a thing -- but assuming we're talking "DOMContentLoaded", then you're absolutely right. It doesn't have anything to do with other resources (images or CSS) being loaded or not. It'll execute as soon as the document is parsed. As for downloading CSS -- it won't prevent your JS from executing, but it'll block page rendering until all the stylesheets have been downloaded and parsed.
- untog 14y agoThat's what I thought. Which means the original post makes very little sense- if your <script> tags are just before </body> there's surely no real delay between that an using DOMContentLoaded?
- cramforce 14y agoThe spec agrees with you, but even MDC does not: https://developer.mozilla.org/en/DOM/DOM_event_reference/DOMContentLoaded https://developer.mozilla.org/en/DOM/DOM_event_reference/DOM... DOMContentLoaded, in all important browsers, does block to wait for CSS. Manipulating the DOM before this event both increases the chance to make changes before first-paint (decreases "jigger" on page load) and gives you the chance to request more resources earlier.
- kevincennis 14y agoWow, that's a total surprise. I guess I never really noticed this because my scripts are always included so much later in the document than my CSS.
- bzbarsky 14y agoDOMContentLoaded does not block to wait for CSS in Firefox.
- deleted 14y ago[deleted]
- bzbarsky 14y ago> As for downloading CSS -- it won't prevent your JS from > executing, It most surely will, in at least Gecko and WebKit. Too many pages have JS that depends on all preceding stylesheets having been loaded.