Surprise async

See Unexpected asynchronous script execution for info about this.

What happens?

When the Load content link is clicked, a fragment (the contents of load.html) is loaded into the DOM.

load.html contains foo.js - which in turn loads bar.js by inserting a script node into the head directly - and an inline script.

The expected behaviour is that foo.js and the inline script are loaded and executed before jQuery.append returns and bar.js to come in to play whenever, but due to nature of javascript events it should be after jQuery.append has returned.

Demo

Load content

Output

Expected output

foo.js completed
load.html inline script completed
append returned
bar.js completed        

Output with Firefox

foo.js completed
append returned
bar.js completed
load.html inline script completed