[whatwg] script postonload

Steve Souders steve at souders.org
Mon Feb 8 14:06:07 PST 2010


I'd like to propose the addition of a POSTONLOAD attribute to the SCRIPT 
tag.

The behavior would be similar to DEFER, but instead of delaying 
downloads until after parsing they would be delayed until after the 
window's load event. Similar to DEFER, this new attribute would ensure 
scripts were executed in the order they appear in the document, although 
it could be combined with ASYNC to have them execute as soon as the 
response is received.

Developers can do this now using JavaScript, but it's complex and 
errorprone. For example, how should the script be added to the document? 
People typically append to the 'head' element, but some pages don't have 
a 'head' element and some browsers don't create a default one. And 
'documentElement' doesn't work in all browsers either. The safest path 
I've seen is to append to ( head || body ). Whether everyone agrees this 
is best, it reveals the complexity developers will have to consider.

Adding this attribute would lower the bar promoting this best practice 
for making web pages faster.

-Steve




More information about the whatwg mailing list