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

Henri Sivonen 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  
>>> 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/




More information about the whatwg mailing list