This is a sketch of how module loading might work in HTML.
-
A "load task" is the end-to-end job of loading a module and all its dependencies, linking everything together, and running the code. It's a high-level concept.
Load tasks come in from
<script type=module>
elements, plus wherever else (maybe a DOM API). The loader can have multiple load tasks in flight at once. -
The loader contains a collection of modules shared by all load tasks. Each module is in one of these states:
- loading - waiting for the network;
- waiting for dependencies - loaded and parsed, not linked;
- ready to link - loaded and parsed, with all dependencies either ready-to-link or complete; or
- complete - fully linked, ready to evaluate or already evaluated
-
Linking happens as eagerly as possible whenever a module arrives off the network. This means that very often we'll be linking one module at a time. In any case, every link set will be a strongly connected component of ready-to-link modules in the dependency graph; and therefore if linking fails, we should discard all the modules that we were trying to link.
-
When a link error or any other error happens, we immediately discard the failed module and everything that depends on it (potentially many modules in various states, and load tasks).
-
Module body evaluation can happen either as eagerly as possible (like linking) or only at the end, when a load task has got everything it needs (the original target module becomes "complete"). The latter approach is a bit more deterministic in terms of what order modules evaluate; maybe we care, maybe not.