Clarification on `async` and `defer` together

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Clarification on `async` and `defer` together

Stu Cox
Not entirely sure if this is the right reference doc: http://www.w3.org/TR/html-markup/script.html – but it doesn't make it clear what should happen if both `async` and `defer` attributes are set on a `<script>` element:

<script src="myscript.js" async defer>

Browsers all seem to give `async` precedence, and I agree that this is the most desirable behaviour, however logically `async` and `defer` aren't necessarily mutually exclusive. If both were applied, it might be reasonable to assume the behaviour might match that of `defer` alone.

Could a note be added to this / any other relevant docs highlighting this behaviour?

The WHATWG spec [1] suggests this behaviour, but isn't incredibly clear about it either.



Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clarification on `async` and `defer` together

Jake Archibald
From http://www.w3.org/TR/html5/scripting-1.html#script "The defer attribute may be specified even if the async attribute is specified, to cause legacy Web browsers that only support defer (and not async) to fall back to the defer behavior"

In step 15 of http://www.w3.org/TR/html5/scripting-1.html#prepare-a-script the defer behaviour is only applied "If the element has a src attribute, and the element has a defer attribute, and the element has been flagged as "parser-inserted", and the element does not have an async attribute", so the defer behaviour doesn't apply if the async attribute is present.

Cheers,
Jake


On 7 July 2013 14:59, Stu Cox <[hidden email]> wrote:
Not entirely sure if this is the right reference doc: http://www.w3.org/TR/html-markup/script.html – but it doesn't make it clear what should happen if both `async` and `defer` attributes are set on a `<script>` element:

<script src="myscript.js" async defer>

Browsers all seem to give `async` precedence, and I agree that this is the most desirable behaviour, however logically `async` and `defer` aren't necessarily mutually exclusive. If both were applied, it might be reasonable to assume the behaviour might match that of `defer` alone.

Could a note be added to this / any other relevant docs highlighting this behaviour?

The WHATWG spec [1] suggests this behaviour, but isn't incredibly clear about it either.




Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clarification on `async` and `defer` together

Stu Cox

On 7 July 2013 17:05, Jake Archibald <[hidden email]> wrote:
From http://www.w3.org/TR/html5/scripting-1.html#script "The defer attribute may be specified even if the async attribute is specified, to cause legacy Web browsers that only support defer (and not async) to fall back to the defer behavior"

In step 15 of http://www.w3.org/TR/html5/scripting-1.html#prepare-a-script the defer behaviour is only applied "If the element has a src attribute, and the element has a defer attribute, and the element has been flagged as "parser-inserted", and the element does not have an async attribute", so the defer behaviour doesn't apply if the async attribute is present.

Cheers,
Jake


On 7 July 2013 14:59, Stu Cox <[hidden email]> wrote:
Not entirely sure if this is the right reference doc: http://www.w3.org/TR/html-markup/script.html – but it doesn't make it clear what should happen if both `async` and `defer` attributes are set on a `<script>` element:

<script src="myscript.js" async defer>

Browsers all seem to give `async` precedence, and I agree that this is the most desirable behaviour, however logically `async` and `defer` aren't necessarily mutually exclusive. If both were applied, it might be reasonable to assume the behaviour might match that of `defer` alone.

Could a note be added to this / any other relevant docs highlighting this behaviour?

The WHATWG spec [1] suggests this behaviour, but isn't incredibly clear about it either.





Ok, that's clear, thanks Jake.

Maybe all that's missing is a similar comment on that working group note then: http://www.w3.org/TR/html-markup/script.html – it's the first Google search result for "w3c script async" and some other related searches.


Stu Cox

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clarification on `async` and `defer` together

Philip Taylor (Webmaster, Ret'd)


Stu Cox wrote:

> Maybe all that's missing is a similar comment on that working group note
> then: http://www.w3.org/TR/html-markup/script.html – it's the first
> Google search result for "w3c script async" and some other related searches.

Nit-picking, but nonetheless a point perhaps worth making :  the
ordering of search results is not fixed; what appears first for
you (when the moon is in the seventh house, and Jupiter aligns
with Mars) may well not be first for someone else, or at some
other (less auspicious ?) time.

Philip Taylor

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clarification on `async` and `defer` together

Stu Cox

On 8 July 2013 13:25, Philip Taylor <[hidden email]> wrote:


Stu Cox wrote:

> Maybe all that's missing is a similar comment on that working group note
> then: http://www.w3.org/TR/html-markup/script.html – it's the first
> Google search result for "w3c script async" and some other related searches.

Nit-picking, but nonetheless a point perhaps worth making :  the
ordering of search results is not fixed; what appears first for
you (when the moon is in the seventh house, and Jupiter aligns
with Mars) may well not be first for someone else, or at some
other (less auspicious ?) time.

Philip Taylor


True, but either way this detail is missing from that document.

Loading...