skip to content

How does a bundling dev server differ from an unbundled native-ESM dev server, and where does each pay its cost as an app grows?

level: middleimportance: should knowfreq 17%

answer

  1. where the module graph is walked
  2. up-front build versus per request
  3. start-up time against request count
  4. transform on demand, cache per file
  5. routes nobody opens

basics

~20 s

A bundling dev server builds the whole module graph before serving, so start-up grows with the app; an unbundled server transforms each module when the browser requests it, so start-up stays fast but page loads grow with the modules imported.

solid answer

~40 s

A **bundling** dev server works like a production build kept in memory: it walks the module graph from the entries, transforms everything, emits bundles and, on each edit, re-emits the affected parts. Its start-up cost scales with the whole app. An **unbundled** server leans on the browser's native ES module loader: the page requests the entry, the browser follows each `import`, and the server transforms each file on demand and caches it. Start-up is nearly independent of app size and an edit re-transforms one module, but a page that touches two thousand modules fires two thousand requests, discovered level by level. A dependency made of hundreds of files would add hundreds more, which is why unbundled servers pre-bundle dependencies.

go deeper

for a junior

Recall that one design builds bundles before serving and the other lets the browser request each module, which the server transforms on demand.

for a middle

Explain where each design spends its time: the whole graph at start-up, or one request and one transform per module the page actually imports.

for a senior

Diagnose a slow dev loop from evidence: a slow start points at the up-front build, a long request waterfall at module count, and you can tell dependency requests from source ones.

for a principal

Judge which dev-serving model suits a codebase's size and page shape, knowing that very large graphs push unbundled tools back toward bundling in development.

## Two ways to serve the same code Every dev server has the same job: get your source into the browser in a runnable form, and keep it current while you edit. There are two basic designs, and they spend their time in different places. Picture an internal **analytics dashboard** with about two thousand source modules and a charting dependency built from several hundred small files. Its developers complain about two things: the server takes a long time to start, and the first page load fires hundreds of requests. Each complaint points at one of the two designs. ## The bundling dev server In its basic form, a **bundling dev server** does the same kind of work as a production build, but keeps the result in memory: - It starts from the **entry points**, follows every static `import` to build the **module graph**, transforms each module, and emits one or more bundles plus a small runtime that knows how to load modules out of them. - It can answer the first request only once that is done, so **start-up time grows with the size of the whole app**, including routes nobody opens during this session. - On save, it re-transforms the changed module and re-emits the affected parts of its output. Caches make this incremental, but the work still scales with how much of the emitted output the change touches. The browser then loads a few bundle files, so a page load is cheap in request count. ## The unbundled native-ESM dev server An **unbundled dev server** lets the browser's own ES module loader walk the graph: 1. The page loads the entry with `<script type="module">`. 2. The browser parses it, finds its `import` statements and requests each one as a URL. 3. The server transforms each requested file **on demand** (stripping types, compiling JSX, rewriting a bare package name into a URL it can answer), caches the result, and sends it back. 4. Steps 2 and 3 repeat down the graph for every module the page actually reaches. Start-up is **nearly independent of app size**: apart from preparing its dependencies, the server does little before the first request, and a route nobody visits is never transformed. An edit invalidates one module's cached transform. The cost moves to the **page load**: two thousand modules means two thousand requests, discovered level by level as each parent arrives and is parsed. ## Where each pays | | Bundling dev server | Unbundled dev server | |---|---|---| | Start-up | grows with the whole graph | nearly flat; dependencies prepared once | | First page load | a few bundle requests | one request per module the page imports | | Cost of a save | re-emit the affected output | re-transform one module | | Routes nobody opens | built, unless compiled lazily | never transformed | | How a hot swap delivers code | through the bundle's runtime | as a module under a fresh URL | Neither design is free. Each one chooses the axis on which the app's size hurts. ## Reading the dashboard's symptoms A slow start with few requests and a quick start with a long waterfall of small requests are different problems: - **Slow start-up** on a bundling server is the whole-graph build. Trimming what the entries import eagerly helps, and so does a server that compiles parts of the graph only when they are first requested. - **Hundreds of requests** on an unbundled server have two sources. Several hundred come from the charting package's internal files, which is the reason unbundled servers **pre-bundle dependencies** into one module each. The rest are the app's own modules, which stay separate on purpose so that a save touches only one of them. - Once a page's request count is dominated by its own source modules, the unbundled design starts to cost real time on every full load. Some unbundled tools are now exploring a development mode that bundles source as well, to cut that network overhead. ## Unbundled does not mean untransformed Browsers run standard JavaScript and resolve only URLs, so TypeScript and JSX syntax, bare specifiers and non-JavaScript imports all still need the server's work. The difference between the two designs is *when* that work happens (per file, on request, or for the whole graph up front), not *whether* it happens. That is also why the unbundled design fits on-demand transforms so well: each file can be transformed alone, while a whole-program check such as type checking cannot, and is left to the editor and the build.

  • If the browser loads modules natively, why does an unbundled dev server still transform the files it serves?
    Browsers run only standard JavaScript and resolve only URLs. TypeScript and JSX syntax must be stripped or compiled, a bare package specifier must be rewritten to a URL the server can answer, and a non-JavaScript import such as a stylesheet must become a module. The server does that per file when the file is requested, and caches the result until the file changes.
  • When does a large app start to outgrow unbundled dev serving?
    When a single page pulls in so many of its own modules that request count, not transform time, dominates a full load: the network panel shows a long waterfall of small requests. Remedies are importing less eagerly on that page, making sure dependencies are pre-bundled, or a development mode that bundles source too, which some unbundled tools are now exploring.

  • An unbundled dev server needs no transforms because browsers run the source as written
  • Unbundled dev serving makes every page load faster, whatever the module count
  • A bundling dev server rebuilds the entire app from scratch on every save
  • Start-up time and page-load time are the same cost measured twice