W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2009

[whatwg] scripts, defer, document.write and DOMContentLoaded

From: Henri Sivonen <hsivonen@iki.fi>
Date: Tue, 4 Aug 2009 13:23:02 +0300
Message-ID: <890FAD6E-49C6-4A6A-B394-C07AF74BF767@iki.fi>
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  
>>> translate
>>> 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  
>> HTML
>> character stream after all the content that is actually there...   
>> That
>> is, immediately before the EOF point.
>
> I don't know how to know that we are before the EOF before we are at  
> the
> 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  
> the
> 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  
> with
> IE, we should be compatible, not introduce yet another behaviour,  
> IMHO.

Considering that the Firefox 3.5 behavior has shipped, it has been  
introduced for practical purposes.

-- 
Henri Sivonen
hsivonen at iki.fi
http://hsivonen.iki.fi/
Received on Tuesday, 4 August 2009 03:23:02 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:15 UTC