concept Frontend & browsers
JavaScript module dependency waterfalls
Independent module downloads can overlap. Follow a dependency from discovery through evaluation to see why fetching it earlier can help, and why its importer may still have to wait.
What it means
JavaScript modules do not have to download one at a time. Once a browser discovers two independent imports, their fetches can overlap. A waterfall appears when one file reveals the next: if the browser first learns about C after downloading A, C has to start later. That delay matters if C is the dependency the rest of the graph is waiting for.
Downloading is only part of the job. Fetching supplies the modules, linking connects their imports and exports, and evaluation runs their code. A module can have all its bytes and still be waiting for a dependency to finish evaluating.
Try it
Simulation: the root module imports A and B, and A imports C. Change only C discovered early from no to yes. This starts C's fetch alongside the root at 0 ms instead of waiting for A. It does not shorten C's 60 ms download. Compare three milestones, all measured from the start of the simulation:
JavaScript module dependency waterfalls
Explain import graph evaluation versus parallel fetch and critical dependencies
Static graph fetches complete first. Dependencies evaluate before importer continuation; a dynamic import begins only when root reaches it.
Dependency graph
- Root importsA and B
- A importsC
- BNo further modeled dependency
Graph
- C discoveryAfter A fetch
- Dynamic fetch (ms)Not evaluated / established
Markers show the actual computed milestones, not continuous download bars or a full JavaScript scheduler. The dynamic import is separate from the initial graph.
Evaluated inputs
- Required scenario evidence
- provided
- Root module fetch
- 50 ms
- Child A fetch
- 100 ms
- Child B fetch
- 80 ms
- C discovered early
- no
- A dependency C fetch
- 60 ms
- Synchronous evaluation per module
- 10 ms
- C asynchronous evaluation wait
- 40 ms
- Root invokes and awaits dynamic import
- no
Not evaluated: Dynamic module fetch duration
Four-node acyclic static graph, unlimited fetch slots, separate single-thread toy evaluation order C sync, B sync, A after C/B, root last. C may suspend for stipulated top-level await; root optionally awaits one dynamic import. No cycles, failure, actual scheduler, cache or fixed ordering claim.
About this model
The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.
Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.
| Milestone | C discovered through A | C discovered early |
|---|---|---|
| C finishes downloading | 210 ms | 60 ms |
| Static graph is ready to evaluate | 210 ms | 150 ms |
| Evaluation finishes | 280 ms | 220 ms |
Why does getting C 150 ms earlier save only 60 ms overall? In both cases, the root finishes downloading at 50 ms. A and B then start together: B finishes at 130 ms and A at 150 ms. With early discovery, C is already available by then, so A becomes the last download. Evaluation cannot start at 60 ms just because C has arrived.
Use Reset to restore discovery through A and the other defaults before comparing another condition. Durations accept whole numbers from 0 to 1000 ms. An invalid input gives no timing result. With valid inputs but Required scenario evidence set to missing, the result is unknown, not a timeline of zero-length events.
After the last download
In the default example, the static graph is ready at 210 ms. The simulation assigns no separate time to linking. From this point on, the important question is not which file arrived first, but which module can finish its work:
- C runs for 10 ms, then suspends at a top-level
awaitfrom 220 to 260 ms. A depends on C and cannot run yet. - B does not depend on C. In this schedule it runs from 220 to 230 ms, during C's wait. B's earlier download did not make it the first module to run.
- When C finishes at 260 ms, A runs until 270 ms. The root then runs until 280 ms.
Now consider the same downloads with C's asynchronous evaluation wait set to 0 ms. The last download still ends at 210 ms. C finishes at 220 ms, but the simulation still schedules B before A. B, A, and the root each take 10 ms, so the finish moves to 250 ms. Removing a 40 ms wait saves 30 ms here: 10 ms of that wait had overlapped with B's work.
A dynamic import has a different starting point. If the root invokes and awaits one in the default example, its fetch starts when the root reaches the call at 280 ms, not when the static graph becomes ready at 210 ms. The extra module finishes downloading at 380 ms; its 10 ms of evaluation brings the finish to 390 ms.
The hint for C moves its fetch completion to 60 ms, but the graph still waits for A at 150 ms. In that case the dependency join, rather than the earliest fetch, determines when evaluation can begin. Inspect the root and module markers separately from the top-level-await completion. A missing required scenario field is an invalid input, not a module that completed instantly.
In practice
When reading a network waterfall, pick the importer whose work you care about. If one of its dependencies started downloading late, check which module first revealed that dependency and whether another download would still have held up the graph. If all the static files had already arrived, look instead for evidence of when the dependency finished evaluating. A gap after the last download does not, on its own, establish a top-level await.
The simulation uses four static modules with no cycles, unlimited fetch slots, and a chosen order for synchronous work. It does not model caching, failures, or a browser's actual scheduler. Its times illustrate a distinction, not a prediction for a site: earlier discovery helps to the extent that it removes a wait on the critical path. To explain when an importer can run, follow that path past the last download to the dependency it needs to finish.
Frequently asked questions
Editorial questions based on the listed sources and explicitly labeled local examples.
Does modulepreload execute a module?
No, it prepares fetch/parse work under its contract.
Can siblings fetch concurrently?
Yes. Once their imports are discovered, independent siblings can have overlapping fetches. The actual schedule depends on the browser and graph discovery.
Does fetch completion equal evaluation completion?
No. Fetching and linking prepare the graph; execution is separate. A dependency suspended at top-level await may delay a dependent module even though its bytes have arrived.
What about cycles?
A dependency cycle does not automatically imply a linking failure: ECMAScript defines special cyclic-module linking and evaluation algorithms. This fixed acyclic graph does not implement those algorithms. A successful link is not a guarantee of completed evaluation.
Sources & model boundaries
Primary references used for this explanation. The interactive example is an educational model, not a live check.
- WHATWG HTML: module script graph
fetch a module script graph. Fetch root and descendants and link graph; preloading alone is not evaluation, and descendant preloading is optional.
Checked .
- ECMAScript module evaluation (living draft)
AsyncModuleExecutionFulfilled; cyclic module evaluation. Async module dependency completion and top-level evaluation promises have defined rules. Cyclic module linking and evaluation are not represented by the toy scheduler.
Checked .