Bug 33018 - load event fires before external scripts have executed
Summary: load event fires before external scripts have executed
Status: RESOLVED DUPLICATE of bug 28783
Alias: None
Product: WebKit
Classification: Unclassified
Component: Page Loading (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-29 06:13 PST by Marcus Better
Modified: 2009-12-29 22:22 PST (History)
1 user (show)

See Also:


Attachments
test case - inline script which adds a script tag (600 bytes, text/html)
2009-12-29 06:13 PST, Marcus Better
no flags Details
the external script (one-liner) referenced by the test case (27 bytes, application/x-javascript)
2009-12-29 06:14 PST, Marcus Better
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Better 2009-12-29 06:13:08 PST
Created attachment 45598 [details]
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 "a executed" output from the external script was deferred to the end, although the script was added at "adding script".

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
Comment 1 Marcus Better 2009-12-29 06:14:15 PST
Created attachment 45600 [details]
the external script (one-liner) referenced by the test case
Comment 2 Alexey Proskuryakov 2009-12-29 22:22:25 PST

*** This bug has been marked as a duplicate of bug 28783 ***