<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>33018</bug_id>
          
          <creation_ts>2009-12-29 06:13:08 -0800</creation_ts>
          <short_desc>load event fires before external scripts have executed</short_desc>
          <delta_ts>2009-12-29 22:22:25 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Page Loading</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>28783</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Marcus Better">marcus</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>175529</commentid>
    <comment_count>0</comment_count>
      <attachid>45598</attachid>
    <who name="Marcus Better">marcus</who>
    <bug_when>2009-12-29 06:13:08 -0800</bug_when>
    <thetext>Created attachment 45598
test case - inline script which adds a script tag

If a script inserts another script tag having a src attribute through a DOM appendChild call, that second script will not run until after the document load event has fired, and after other scripts in the HEAD or BODY have executed.

This causes problems when scripts included later in the document have dependencies on the dynamically loaded script, which is typically the case with JavaScript libraries that the page needs.

This deviates from Firefox 3.5 behaviour. I suspect it may also conflict with the WHATWG draft [1] which seems to require that a script must be run synchronously when its script element is inserted.

See the attached test case, in which an inline script inserts another script tag for an external file. Running the test case in Chrome 4.0.266.0 (WebKit 532.6) or Arora 0.10.1 (WebKit 532.4) on Linux gives this console output:

  inline HEAD
  adding script
  inline HEAD 2
  inline BODY
  body load
  a executed

We can see that the &quot;a executed&quot; output from the external script was deferred to the end, although the script was added at &quot;adding script&quot;.

In contrast, Firefox 3.5 Linux gives this order:

  inline HEAD
  adding script
  a executed
  inline HEAD 2
  inline BODY
  body load

(Another amusing fact is that the picture changes if the external script is inserted with document.write instead of the DOM method. In that case, WebKit behaves identically to Firefox. I have a bunch of different test cases for various other ways of nesting the script inclusions.)

[1] http://www.whatwg.org/specs/web-apps/current-work/#script</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>175531</commentid>
    <comment_count>1</comment_count>
      <attachid>45600</attachid>
    <who name="Marcus Better">marcus</who>
    <bug_when>2009-12-29 06:14:15 -0800</bug_when>
    <thetext>Created attachment 45600
the external script (one-liner) referenced by the test case</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>175799</commentid>
    <comment_count>2</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2009-12-29 22:22:25 -0800</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 28783 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>45598</attachid>
            <date>2009-12-29 06:13:08 -0800</date>
            <delta_ts>2009-12-29 06:13:08 -0800</delta_ts>
            <desc>test case - inline script which adds a script tag</desc>
            <filename>script-exec-order-test.html</filename>
            <type>text/html</type>
            <size>600</size>
            <attacher name="Marcus Better">marcus</attacher>
            
              <data encoding="base64">PGh0bWw+CiAgICA8aGVhZD4KICAgICAgICA8dGl0bGU+c2NyaXB0IGV4ZWN1dGlvbiBvcmRlciB0
ZXN0PC90aXRsZT4KICAgICAgICA8c2NyaXB0IHR5cGU9InRleHQvamF2YXNjcmlwdCI+Y29uc29s
ZS5sb2coImlubGluZSBIRUFEIik8L3NjcmlwdD4KICAgICAgICA8c2NyaXB0IHR5cGU9InRleHQv
amF2YXNjcmlwdCI+CmNvbnNvbGUubG9nKCJhZGRpbmcgc2NyaXB0Iik7CnZhciBlbCA9IGRvY3Vt
ZW50LmNyZWF0ZUVsZW1lbnQoIlNDUklQVCIpOwplbC50eXBlID0gInRleHQvamF2YXNjcmlwdCI7
CmVsLnNyYyA9ICJhLmpzIjsKZG9jdW1lbnQuZ2V0RWxlbWVudHNCeVRhZ05hbWUoIkhFQUQiKVsw
XS5hcHBlbmRDaGlsZChlbCk7Cjwvc2NyaXB0PgogICAgICAgIDxzY3JpcHQgdHlwZT0idGV4dC9q
YXZhc2NyaXB0Ij5jb25zb2xlLmxvZygiaW5saW5lIEhFQUQgMiIpPC9zY3JpcHQ+CiAgICA8L2hl
YWQ+CiAgICA8Ym9keSBvbmxvYWQ9ImNvbnNvbGUubG9nKCdib2R5IGxvYWQnKSI+CiAgICAgICAg
PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPmNvbnNvbGUubG9nKCJpbmxpbmUgQk9EWSIp
PC9zY3JpcHQ+CiAgICA8L2JvZHk+CjwvaHRtbD4K
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>45600</attachid>
            <date>2009-12-29 06:14:15 -0800</date>
            <delta_ts>2009-12-29 06:14:15 -0800</delta_ts>
            <desc>the external script (one-liner) referenced by the test case</desc>
            <filename>a.js</filename>
            <type>application/x-javascript</type>
            <size>27</size>
            <attacher name="Marcus Better">marcus</attacher>
            
              <data encoding="base64">Y29uc29sZS5sb2coImEgZXhlY3V0ZWQiKTsK
</data>

          </attachment>
      

    </bug>

</bugzilla>