[whatwg] scripts, defer, document.write and DOMContentLoaded
hsivonen at iki.fi
Tue Aug 4 03:23:02 PDT 2009
On Aug 1, 2009, at 02:50, Ian Hickson wrote:
> On Tue, 21 Jul 2009, Boris Zbarsky wrote:
>>> I don't really understand what your proposal would actually
>>> to, in precise spec terms.
>> I haven't internalized your parsing algorithm rules, but my intuition
>> given the one compat requirement I know of here (not blowing away
>> documents in cases where IE doesn't blow them away) is that deferred
>> scripts should be treated as if the <script> tags appeared in the
>> character stream after all the content that is actually there...
>> is, immediately before the EOF point.
> I don't know how to know that we are before the EOF before we are at
> EOF, and I am very dubious about tokenising after hitting the EOF. For
> example, document.close() inserts an EOF, and I don't feel comfortable
> saying that after document.close() you can still document.write() to
> same document.
Have a piece of parser state for "stream ended". It's initially false.
document.close() turns it true. The end of the network stream turns it
true. When it gets set to true, schedule a task for calling the parser
again for inspecting the flag.
When there are no pending scripts and "stream ended" is true, emit
EOF. If there are pending scripts and 'stream ended' is true, make
sure the script execution machinery pumps the parser again to avoid
busy-waiting from rescheduling tasks repeatedly.
> It's what IE does, and you found that we needed to be compatible
> with IE
> for this case, as far as I can tell. When we want to be compatible
> IE, we should be compatible, not introduce yet another behaviour,
Considering that the Firefox 3.5 behavior has shipped, it has been
introduced for practical purposes.
hsivonen at iki.fi
More information about the whatwg