Google Chrome executing script in wrong order
Reported by
mikhail....@gmail.com,
Mar 14 2016
|
||||||||||
Issue descriptionUserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.18 Safari/537.36 Steps to reproduce the problem: 1. open my demonstration http://bbb.sy24.ru/ 2. and see console 3. What is the expected behavior? Expected behavior you can see in Firefox: *** extern.js:20:1 2 js.php:1:1 4 js.php:1:1 6 js.php:1:1 8 js.php:1:1 10 js.php:1:1 1 js.php:1:1 3 js.php:1:1 5 js.php:1:1 7 js.php:1:1 9 js.php:1:1 *** extern.js:20:1 2 js.php:1:1 4 js.php:1:1 6 js.php:1:1 8 js.php:1:1 10 js.php:1:1 1 js.php:1:1 3 js.php:1:1 5 js.php:1:1 7 js.php:1:1 9 js.php:1:1 Some stufff /:19:3 boroda!!! What went wrong? Chrome execute dynamically added script after all scripts, but must execute immediately after first and second extern.js. Did this work before? N/A Chrome version: 50.0.2661.18 Channel: dev OS Version: Fedora 23 Flash Version: Shockwave Flash 21.0 r0
,
Mar 14 2016
notice what on another machine, first page load seems correct, but second and follow incorrect.
,
Mar 14 2016
,
Mar 14 2016
Not V8 related, we simply get the code.
,
Mar 16 2016
Able to reproduce the issue on Windows 7, Ubuntu 14.04 and Mac OS 10.11.3 using chrome stable M49-49.0.2623.8. Observed the script executes in a different order compared to firefox. This is a non-regression issue seem from M35-35.0.1851.0, Hence marking it as untriaged.
,
Mar 21 2016
document.createElement is not guaranteed to be synchronous (for that you need document.write). bmcquade@ can you confirm this is WAI?
,
Mar 21 2016
correct, scripts added via createElement are executed async, with no guaranteed order. there is some support for executing scripts asynchronously but in order relative to other async-in-order scripts. mikhail, you can learn more about script ordering here: http://www.html5rocks.com/en/tutorials/speed/script-loading/ and here: https://html.spec.whatwg.org/multipage/
,
Mar 21 2016
and just to clarify, FF may execute these in order, but that's due to an implementation detail specific to Firefox, and not guaranteed across all browsers. You can't depend on execution order of scripts inserted in this way.
,
Mar 21 2016
,
Mar 21 2016
Aren't the script-inserted script elements using async=false here? I think the testcase is running into unpredictable behavior by issuing too many requests to the same origin, but haven't looked too closely.
,
Mar 21 2016
Thank you sigbjornf, I missed the async=false detail. re-opening for further investigation.
,
Mar 21 2016
Looking at the page, the ordering guarantees should be:
the following scripts should execute in order relative to one another:
<script src="extern.js" />
<script id="s1" src="js.php?num=1&delay=10" />
<script id="s3" src="js.php?num=3&delay=8" />
<script id="s5" src="js.php?num=5&delay=6" />
<script id="s7" src="js.php?num=7&delay=4" />
<script id="s9" src="js.php?num=9&delay=2" />
<script src="extern.js" />
<script id="s1" src="js.php?num=1&delay=10" />
<script id="s3" src="js.php?num=3&delay=8" />
<script id="s5" src="js.php?num=5&delay=6" />
<script id="s7" src="js.php?num=7&delay=4" />
<script id="s9" src="js.php?num=9&delay=2" />
and, separately, all scripts inserted dynamically that use async=false should execute in the order they are inserted
However there are no execution order guarantees between these two groups. Parser blocking scripts and async-in-order scripts are processed in independent queues. The HTML5 spec has more details.
mikhail, are you seeing cases where either the parser-blocking scripts (those loaded via <script> tags in the HTML markup) are not executing in the order they appear in the HTML markup?
or, are you seeing cases where async-in-order scripts are not executing in the order they are inserted into the document?
If you do see either of these happening it's a bug.
But there are no guarantees about the execution order of parser blocking scripts relative to async-in-order scripts or vice versa.
,
Mar 21 2016
,
Mar 23 2016
Ok, my story started with adaptation tinyMCE and CKeditor for XHTML. Main problem here that in XHTML mode not allow use document.write. Their loaders used document.write for dynamic scripting. I rewrote loader but tinyMCE started work only in Firefox. I wondered why this is so and so was made an example which I gave in the first post. but really main task for me so that the newly added scripts are executed in the order of their location in the DOM. <script src="1.js"/> <script src="2.js"/> <script src="3.js"/> This means that if the '<script src = "2.js" />' was added between '<script src = "1.js" />' and '<script src = "3.js" />' and then it should be executed after '<script src = "1.js" />', but before '<script src = "3.js" />'. I made more interesting example: http://b02.sy24.ru/ But I have not been able to achieve this behavior is not in one of the browsers :( We need a real replacement document.write for XHTML.
,
Mar 24 2016
Thank you for providing more feedback. Assigning to requester "bmcquade@chromium.org" for another review. For more details visit https://sites.google.com/a/chromium.org/dev/issue-tracking/autotriage - Your friendly Sheriffbot
,
Mar 29 2016
Ah I see. I'm sorry there's not a way to dynamically load scripts in a fixed order relative to other scripts declared in markup in XHTML.
I think the best you will be able to do is load all of the scripts needed on the page using the 'async in order' technique:
var script = document.createElement('script');
script.src = src;
script.async = false;
document.head.appendChild(script);
This will preserve execution order of the scripts. Note that the execution order in this case is determined by insertion order, rather than the ordering of the script elements as you insert them into the DOM. For script elements inserted into the DOM dynamically, their position in the DOM has no impact on the order in which they execute.
RE: providing a document.write for XHTML, I think that's unlikely. document.write is generally considered to be an undesirable feature of the web platform, so there is a desire to see it used less rather than more.
I'm going to close this out since it doesn't sound like there's a bug in Chrome.
|
||||||||||
►
Sign in to add a comment |
||||||||||
Comment 1 by mikhail....@gmail.com
, Mar 14 2016