ESM modules are loaded sequentially by design
May 8, 2025
Today I learned: even when delivered over HTTP/2—which allows multiplexing and parallel resource fetching—ESM (ECMAScript Modules) are still loaded sequentially by design. This might seem counterintuitive at first. HTTP/2 enables the browser to fetch multiple files simultaneously over a single connection, so it’s reasonable to expect that modules could be fetched and evaluated in parallel. But ESM prioritizes determinism and predictability over raw speed.
When a JavaScript module imports other modules, the browser must parse the import graph, resolve dependencies, and then execute them in the exact order required by the dependency tree. This means the browser waits until each module and its transitive dependencies are fully fetched and evaluated before continuing. Even with aggressive preloading and HTTP/2 multiplexing, the evaluation phase remains inherently sequential to preserve the correct initialization order. This reflects a core principle of ESM: modules are static, meaning their imports are known ahead of time and executed in a top-down, well-ordered fashion.