This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 25470 - [imports]: improve description of async to clarify execution order
Summary: [imports]: improve description of async to clarify execution order
Status: RESOLVED MOVED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on: 25467
Blocks: 20683
  Show dependency treegraph
 
Reported: 2014-04-25 23:14 UTC by Steve Orvell
Modified: 2015-07-06 08:08 UTC (History)
5 users (show)

See Also:


Attachments

Description Steve Orvell 2014-04-25 23:14:04 UTC
The spec should make it more clear that imports marked with async will not delay execution (of scripts, stylesheets, or custom element upgrades) due to any other async imports.

<link rel="import" href="a.html" async>
<link rel="import" href="b.html">
<link rel="import" href="c.html">
<link rel="import" href="d.html" async>

The only guarantee in the above setup is that 'b.html' is executed before 'c.html'. The async imports 'a.html' and 'd.html' may execute in any order with respect to each other and other non-async imports.
Comment 1 Glenn Maynard 2014-04-26 00:56:49 UTC
Is there really a need to support async?  It's much better to limit it to <script defer>-like behavior (which is what you described for b.html and c.html), where loading doesn't block but things always happen in the same order.  Web APIs shouldn't be nondeterministic.
Comment 2 Morrita Hajime 2014-04-28 21:52:08 UTC
Unlike <script>, imports machinery has many reasons to be used by non-async [1].
@async is for things that are self contained and don't care about the order.
It is as to no blocking other things.
If the order is a concern, sync is better option.

[1] https://gist.github.com/omo/9986103
Comment 3 Glenn Maynard 2014-04-28 22:10:01 UTC
I'm not saying it shouldn't support asynchronous loading, I'm asking whether it should really support the <script async> model instead of the <script defer> model.

<script async> means "load the resource asynchronously, and run the script as soon as it's ready".  <script defer> means "load the resource asynchronously, and run the script in the order it was added (at the end of parsing)".  If you have multiple <script defer>s, they all load asynchronously, but later ones don't execute until earlier ones, even if the network load happens to finish first.

With the defer model, b.html, c.html, a.html and d.html would always be executed in that exact order (sync before defer, then defer in the order added), which is much easier to test--you don't have to test every possible load order to be certain your page always works, since the load order is always predictable.

It seems like <script async> was a bad idea which <script defer> fixed, and now this is making the same mistake.
Comment 4 Morrita Hajime 2014-04-28 22:51:42 UTC
(In reply to Glenn Maynard from comment #3)
> <script async> means "load the resource asynchronously, and run the script
> as soon as it's ready".  <script defer> means "load the resource
> asynchronously, and run the script in the order it was added (at the end of
> parsing)".  If you have multiple <script defer>s, they all load
> asynchronously, but later ones don't execute until earlier ones, even if the
> network load happens to finish first.
> 
> With the defer model, b.html, c.html, a.html and d.html would always be
> executed in that exact order (sync before defer, then defer in the order
> added), which is much easier to test--you don't have to test every possible
> load order to be certain your page always works, since the load order is
> always predictable.
> 
> It seems like <script async> was a bad idea which <script defer> fixed, and
> now this is making the same mistake.

<script async> is bad idea because there is no way to declare the dependency to the loaded script. For imports, the import itself can contain a set of imports to require its dependency. So it's much easier for imports to be self contained. This is big difference between <scripts> and imports.

Imports support textual ordering mainly for consistency of other platform bits. Imports shouldn't have to rely on that ordering and so do not well defined imports. Dependency is no longer have to be a list. Now it can be a tree.

One good thing not to enforce ordering for @async is that imports that is loaded faster can rendered earlier, without waiting other imports. This is important for mashup-like scenario. Tweet buttons don't to Like buttons and vice versa.
Comment 5 Morrita Hajime 2014-04-28 22:54:25 UTC
By the way, I understand the unpredictability concern.
That's why we're polishing sync scenario so that it blocks as little as possible.
Comment 6 Hayato Ito 2015-07-06 08:08:29 UTC
Moved to https://github.com/w3c/webcomponents/issues/218