-
Notifications
You must be signed in to change notification settings - Fork 85
script[defer] doesn't work in IE<=9 #42
Comments
kyle added....
|
To give more context to the above list of
|
I made a test which seems to confirm the following:
http://dl.dropbox.com/u/513327/domload_defer.html (load and reload it in Firefox 5 and then load in Chrome) Chrome 12 results: Update: I removed the Cuzillion tests on visual rendering blocking because they were invalid. |
Isn't blocking the visual rendering only supposed to occur with non- In regards to if( document.createEvent ) {
var evt = document.createEvent("MutationEvents");
evt.initMutationEvent("DOMContentLoaded", true, true, document, "", "", "", 0);
document.dispatchEvent(evt);
} |
I think that might cause problems with some handlers as it's generally assumed |
FWIW:
|
Are the logical next steps to: |
I ran your DCL test page (http://dl.dropbox.com/u/513327/domload_defer.html) in IE9: |
The question is: What is our goal here (in regards to H5BP)? Upgrading all scripts which are already aligned at the document's end with What we could do is do some tests just for fun and curiosity (which might be reason enough ;) |
Isn't the visual rendering blocking/non-blocking that @jdalton reported expected? The report HTML on the Cuzillion page comes after the external script. So doesn't it make sense that it would be blocked without |
@robflaherty Good point. This: …appears after the last |
If the As it stands, |
If "defer" is made the default, will developers get confused that their inline JS is processed before the deferred (external) scripts? http://www.artzstudio.com/files/Boot/test/benchmarks/script.defer.html Most sites have a need for inline JS, for example Google Analytics code, page specific initialization, etc.
|
Couple of other points... it may be worth noting that stylesheet downloading blocks Example: http://stevesouders.com/cuzillion/?c0=hc1hfff2_0_f&c1=bj1hfft1_0_f&t=1313073628 Another thing to keep in mind when testing is WebKit's PreloadScanner, which prefetches scripts and runs in just about every real-world scenario. In more cases it's surely tangential but there may be some wacky test cases where it affects results. |
I've just run across an issue where I'm loading jquery and jquery-ui in succession, using script tags with Has anyone else seen |
can you run a couple of tests with the test page in some IE9 test nodes on Webpagetest.org and publish links to results here? |
Here's my test page: http://test.getify.com/test-ie-script-defer/ Try that in IE<=9, you get "Fail!". Try it in any other browser-type, get "Pass!". Try it in IE10p2, get "Pass!". Here's some results, as you requested, from WPT.org (IE9-Fail) http://www.webpagetest.org/result/110823_TH_1D7F4/ (IE8-Fail) http://www.webpagetest.org/result/110823_PD_1D7F9/ (IE7-Fail) http://www.webpagetest.org/result/110823_RE_1D7FH/ (IE6-Fail) http://www.webpagetest.org/result/110823_JK_1D7FP/ (Chrome-Pass) http://www.webpagetest.org/result/110823_XE_1D7G1/ |
txs Kyle. Would love to get involved and participate in further, deeper research. Fyi, the IE8 waterfall (only looked at this one) shows requests being aborted. |
yeah, the IE8 waterfall does indeed show the requests being canceled, which is inexplicable to me because the structure of the test document is exactly as the article you linked to prescribes (that is, the charset declaration is the first tag in the head, as it should be). Moreover, the IE6,7, and 9 waterfalls do NOT show the canceled loads, so the canceled load is most likely not the culprit (although is certainly a performance concern). Even in a canceled load/reload of a script, as the IE8 waterfall shows, one would still expect the browser to hold off on running the correctly downloaded script ("init.js") until it could re-request and successfully download the other two and run them. No matter how you slice it, not running them in order is a failure. Order preservation is well-defined in the spec for If IE10 indeed has fixed this (it seems so, but not confirmed), I won't use BTW, my suspicion (unconfirmed) is that maybe it has something to do with loading all 3 scripts from different domains. But I have no explanation as to why that would cause execution order to fail. |
FYI, I’ve attempted to simplify @getify’s test case here: http://jsbin.com/mathias/inebat Oddly, it seems to pass for me in IE8. Did I do anything wrong? Update: See @nicjansma’s explaination below. This test passes in IE8 because I didn’t use any code that triggers HTML parsing. |
FYI: I'm now not convinced (entirely) that this is IE's fault. I put a console.log() at the top of both jquery, and jquery-ui (both hosted locally now) and they "run" in the right order, but the |
OK, this is officially one of the weirdest WTF's I've ever seen... Check this out (in any IE<=9): http://test.getify.com/test-ie-script-defer/index-2.html Look closely at the log box there. It says:
In other words, it appears that IE is suspending execution of jQuery somewhere mid-file, switching over to execute jQuery-UI, finishing it, THEN switching back to jQuery to finish it. I'm really quite shocked at this. What happened to single-threaded "run-to-the-end" JavaScript? |
clarification: i wrapped a try/catch around the entire contents of jquery-ui.js because of that "reference" error, so what's actually happening is that jquery-UI is stopping with the error almost immediately, being caught in the try/catch, and at least allowing the final |
Side note on script-defer from a bit earlier in the thread... According to spec, script-defer is NOT defined for inline script blocks, contrary to popular belief: http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#attr-script-defer
|
That's what I was trying to say earlier in the thread. Race conditions can exist if you defer external scripts required by inline scripts. With defer: http://www.artzstudio.com/files/defer-test/defer.html Without: http://www.artzstudio.com/files/defer-test/normal.html |
Yea, that's why I also stated "some (officially) non-deferable inline-script." <- no defer allowed :) Kyle, maybe the bug you see results from the new Chakra engine being able, or trying to, execute multiple scripts in parallel on multicore machines. See: http://technet.microsoft.com/en-us/library/gg699435.aspx
and http://msdn.microsoft.com/en-us/ie/ff468705.aspx#_cfperformance
I'd guess that when you bind IE9 to only one single CPU-core everything will be back to normal. You do that by opening the Task Manager (Strg + Shift + Esc), go to processes, right click the corresponding IE9 process, chose "Set Affinity", uncheck all but one checkbox. Or see here: |
Okay, forget it. You get the bug not in IE9. |
This is a known bug in IE9 that has been fixed in IE10. In this case, after the page is done loading and IE starts to run the defer scripts, the first script, jQuery is run, and it starts building the .support object. During this time, it sets an .innerHTML, which (incorrectly) causes IE to think it needs to look for more defer scripts to run. IE starts executing the second defer script, jQuery UI, before the first script has completed, so the jQuery namespace isn't available. |
@nicjansma -- do you have any link about that? never heard about this bug before. Also, are you aware/can you confirm that it affects all IE<=9? I dunno about anyone else, but that bug pretty much seals |
Because my organization supports IE9 and I've been asked to look into this, I figure I should throw in a comment even if it's a year ahead. I just put together a test of this in an IE9 VM, and couldn't reproduce the issue discussed; in fact I'm currently considering simply universally adding the "defer" attribute to our scripts. |
I wouldn't build my production strategy on such false assumptions, but YMMV. As far as I'm concerned, everything here about Even in IE10+, |
Didn't you just write this one earlier in the thread? Any syncronicity between a defer+src script with an inline script (ie, something running a JQuery function) is coincidential, and undefined browser behavior. I tend to think of inline scripts (as in, inline between pieces of content, not a single inline script in head that configures your libraries) as archaic deprecated behavior, like conditional HTML comments; , so I'm not surprised that having them in place breaks newer script-loading features. |
IE <=9 doesn't guarantee the order of execution of script[defer] (h5bp/lazyweb-requests#42)
IE <=9 doesn't guarantee the order of execution of script[defer] (h5bp/lazyweb-requests#42)
Hello, what is the difference between <script async=''async'' & <script async='' |
None, really...they're both syntactically accepted because some HTML-writing programs don't follow the Boolean nature of attributes, and because it's required for valid XML. Attributes like "async" or "disabled" don't actually require an equals sign. It's valid to write <script async> or . Anything inside the equals is pretty much ignored. When checking for those Booleans, JS code usually checks "element.hasAttribute(x)" rather than "element.getAttribute()", so even if it registers as an empty string, it will turn out true. |
For posterity sake, let's not clutter up this thread with general support inquiries about web platform features. Please take this discussion to stackoverflow or some other forum where it's more appropriate, and remove the messages here. |
An user reported the suggested fix didn't work for him. If other users could confirm this, the original post should be edited so that people who land on it are not misled ;) |
…o front-end-performance-checklist-2019-pdf-pages-center
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had recent activity. Thank you for your contributions. |
(Edited 2012.03.01)
TL;DR: don't use
defer
for external scripts that can depend on eachother if you need IE <= 9 supportThere is a bug in IE<=9 (confirmed, below, by an IE engineer) where if you have two scripts such as...
And the first script modifies the dom with
appendChild
,innerHTML
, (etc.), the second script can start executing before the first one has finished. Thus, a dependency between the two will break.The details of this limitation begin at this comment
This essentially means that
script[defer]
cannot be used in most cases unless you have dropped IE8 and IE9 support. If, however, you can UA sniff to serve script[defer] to all browsers except IE6-9, that will net you large performance wins.Steve Souders indicated there may be a hack of inserting an empty
<script></script>
tag between the two tags that may address this problem. Research to be done…original post follows:
# comprehensive research and article on script @defer
@defer
scripts execute when the browser gets around to them, but they execute in order. this is awesome for performance.it's also awesome that it's been in IE since IE5.
but, we're lacking a little bit of comprehensive research on this..
kyle simpson thinks there may be some edge case issues with defer... from this h5bp thread...
it'd be excellent to get a great summary of the full story across browsers and these issues so we can use defer confidently.
see also:
- @aaronpeters @Schepp
The text was updated successfully, but these errors were encountered: