<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hello, I am looking at using WebKit as an HTML rendering/JS host in a native C++ application. Currently the application uses IE via the WebOC. I have WebKit running and loading the HTML / JS but I have encountered a problem and I was wondering
if you could think of any work-arounds.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Problem: The execution order of scripts added to the DOM via insertBefore seems to be after scripts statically declared in the HTML file.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I don’t have any doubts that WebKit is proper here vis-à-vis the standard (though I couldn’t find anything specific in the standard that made it clear one way or another). Basically what I see is that scripts dynamically injected seem to
be executed AFTER the statically declared ones, even if inserted before them and even if the dynamically injected ones set async to false on the created script node.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In IE it seems different. Imagine this scenario, in the root HTML page we have:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> <script src="A.js" type="text/javascript"></script><o:p></o:p></p>
<p class="MsoNormal"> <script src="B.js" type="text/javascript"></script><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">And assume A.js has JS code that injects another script, let’s call it A1, (that it dynamically locates, which is why it can’t be declared in the markup).
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In IE I see this execution order:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">A -> A1 -> B<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In WebKit I see this execution order<o:p></o:p></p>
<p class="MsoNormal"><br>
A-> B -> A1<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I speculate IE is executing the scripts in the HTML in order and the injection done by A is causing the new script to show up and be executed before it gets to script B. WebKit on the other hand seems to be enqueing all the scripts from
the HTML and then executing them in order, so when it hits A and A injects a new script it gets placed at the end of the execution queue and executed after B.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This is a problem because in our case A1 injects a bunch of global functions/properties that B depends on, so if B executes first, well things don’t go so well.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I could indirect B so it simply did a dynamic injection of its contents like A does, call it B1 (I presume that would mean B1 would then be executed after A1), but that is non-ideal if there are a lot of scripts involved.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Ryan<o:p></o:p></p>
</div>
</body>
</html>