[whatwg] Apply script.defer to internal scripts

Ian Hickson ian at hixie.ch
Mon Jun 4 17:19:29 PDT 2007


On Tue, 27 Mar 2007, Kristof Zelechovski wrote:
>
> I understand that the async attribute must depend on the src attribute 
> because it is needed and meaningful only when the script element is 
> loaded from an external source; however, the advantage of using the 
> defer attribute is not limited to that case.
> 
> Consider the following example:
> 
> <script type="text/javascript" defer>
> function ha8validate(p5event) { return true }
> document.forms[0].onsubmit = ha8validate
> </script>
> 
> The script embedded here is so short and specific that it makes no sense 
> relaying it to an external location; however, if the script is not 
> deferred, the script fails with an exception at run time because the 
> document body is not constructed yet.
> 
> Therefore, the defer attribute can be meaningful without the src 
> attribute and the dependency should be removed.

I have removed the dependency. You can now specify "defer" even without 
the "src" attribute.

I've also removed the restriction for "async", because you might want to 
run a set of scripts in a particular order, with one of them being 
external and async, and another being internal. The only way to guarentee 
the internal one runs immediately after the external one is to make the 
internal one async too.


On Thu, 29 Mar 2007, Gareth Hay wrote:
>
> Does it not follow that to be "more consistent, logical, better style, 
> whatever." you should wrap your code in a function that is called 
> onload?
> 
> Isn't that what onload is for? being triggered after the page has 
> loaded?

This doesn't preclude us allowing the other.


On Thu, 29 Mar 2007, Alexey Feldgendler wrote:
>
> How is this better than putting the <script> immediately beefore 
> </body>, which already works today?

It might not be better, but that's not a reason to disallow it.


On Tue, 3 Apr 2007, Hallvord R M Steen wrote:
> 
> There is no real advantage to the defer attribute since in HTML4 it is 
> only advisory, the UA is not required to actually defer the script 
> execution, and some implementations only defer it until seeing the next 
> SCRIPT element in the source. Relying on it the way your use case does 
> will work in very few browsers, and specifying this in HTML5 would 
> increase backwards incompatibility for a very minimal gain.

HTML5 defines it exactly.


On Tue, 3 Apr 2007, Stewart Brodie wrote:
> 
> My implementation will execute the script immediately if it was inline, 
> and execute it as soon as the whole script is available (obtained from 
> filesystem/network) otherwise.  As far as I understood the 
> specification, the DEFER simply indicates to the HTML parser that it can 
> continue parsing the HTML without waiting to see if the script is going 
> to insert additional content - i.e. the script will not use 
> document.write (and friends).

HTML5 defines this more exactly than HTML4.


Cheers,
-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list