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

Hi all,

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.

Gecko currently follows the spec, but is the only browser that does
so. We are not aware of any sites that break because of this.

The main use case for wanting to support scripts getting appears to be
wanting to abort JSONP loads. Potentially to issue it with new
parameters. This is a decent use case, but given the racyness
described above in webkit, it doesn't seem like a reliable technique
in existing browsers.

So the questions are:

1. Should we keep the spec as it currently stands?
2. Are browsers willing to follow the specced behavior?
3. Do we want to support the use-case of abourting JSONP loads?
4. If we do, should we use the "existing" technique even though it'll
fail intermittently in existing browsers and comes with other risks.
Or should we define a new API for this use case (which could be
feature detected).

/ Jonas

Received on Friday, 2 December 2011 11:27:51 UTC