[whatwg] Behavior when <script> is removed from DOM

Edward O'Connor eoconnor at apple.com
Fri Dec 2 14:59:10 PST 2011

Jonas wrote:

> Currently HTML5 defines that a <script src="..."> element that is
> inserted into the DOM should always execute if the load succeeds. Even
> the the element is removed from the Document before it is executed.
> See
> http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#script-processing-src-prepare
> This makes a lot of sense to me since otherwise we'll introduce a race
> condition where if the load happens quickly enough the script will
> execute despite being later removed. In other words, a piece of DOM
> which is removed may or may not cancel any <script>s inside it.
> In webkit things are even worse. It appears that if you insert a
> <script> in the DOM and *immediately* remove it, before returning to
> the event loop, it still sometimes executes. I.e. webkit appears to
> always be exhibiting racy behavior.

Yeah, gross. I've filed https://bugs.webkit.org/show_bug.cgi?id=73707 to
track this in WebKit.


More information about the whatwg mailing list