Re: Clarification on `async` and `defer` together
Jake Archibald <[email protected]> Sun, 7 Jul 2013 17:05:39 +0100
| Newsgroups | gmane.comp.web.html.general |
|---|---|
| Message-ID | <CAJ5xic9paR9Bx5YE3TLvo7z7=2HzxzSpDOmTDopkfzz6z_s6Rw@mail.gmail.com> |
--f46d043be0305f6c9c04e0ee198f Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable >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-scriptt= he 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 <[email protected]> wrote: > Not entirely sure if this is the right reference doc: > http://www.w3.org/TR/html-markup/script.html =E2=80=93 but it doesn't mak= e it > clear what should happen if both `async` and `defer` attributes are set o= n > a `<script>` element: > > <script src=3D"myscript.js" async defer> > > Browsers all seem to give `async` precedence, and I agree that this is th= e > 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. > > > [1] > http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.h= tml > > --f46d043be0305f6c9c04e0ee198f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">From=C2=A0<a href=3D"http://www.w3.org/TR/html5/scripting-= 1.html#script">http://www.w3.org/TR/html5/scripting-1.html#script</a> "= ;The defer attribute may be specified even if the async attribute is specif= ied, to cause legacy Web browsers that only support defer (and not async) t= o fall back to the defer behavior"<div> <br></div><div style>In step 15 of=C2=A0<a href=3D"http://www.w3.org/TR/htm= l5/scripting-1.html#prepare-a-script">http://www.w3.org/TR/html5/scripting-= 1.html#prepare-a-script</a> the defer behaviour is only applied "If th= e element has a src attribute, and the element has a defer attribute, and t= he 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.</div> <div style><br></div><div style>Cheers,</div><div style>Jake</div></div><di= v class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On 7 July 2013 1= 4:59, Stu Cox <span dir=3D"ltr"><<a href=3D"mailto:[email protected]"= target=3D"_blank">[email protected]</a>></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>Not entirely sure if t= his is the right reference doc: <a href=3D"http://www.w3.org/TR/html-markup= /script.html" target=3D"_blank">http://www.w3.org/TR/html-markup/script.htm= l</a> =E2=80=93 but it doesn't make it clear what should happen if both= `async` and `defer` attributes are set on a `<script>` element:</div= > <div><br></div><div><script src=3D"myscript.js" async defer>= ;</div><div><br></div><div>Browsers all seem to give `async` precedence, an= d I agree that this is the most desirable behaviour, however logically `asy= nc` and `defer` aren't necessarily mutually exclusive. If both were app= lied, it might be reasonable to assume the behaviour might match that of `d= efer` alone.</div> <div><br></div><div>Could a note be added to this / any other relevant docs= highlighting this behaviour?</div><div><br></div><div>The WHATWG spec [1] = suggests this behaviour, but isn't incredibly clear about it either.</d= iv> <div><br></div><div><br></div><div>[1] <a href=3D"http://www.whatwg.org/spe= cs/web-apps/current-work/multipage/scripting-1.html" target=3D"_blank">http= ://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html</a= ><br> </div><div><br></div></div> </blockquote></div><br></div> --f46d043be0305f6c9c04e0ee198f--