Vite

How Vite serves native ES modules during development

Compare Webpack startup with Vite's native ESM server, from on-demand transforms and conditional HTTP caching to module-level hot updates.

How Vite serves native ES modules during development

In the 1,480-file project measured here, the Webpack 5 development server took 14.24 seconds to become ready and Vite 6 took 184 milliseconds. The two servers put work on different sides of the first browser request.

The startup comparison uses Webpack 5 and Vite 6. The production build notes cover the subsequent move to Rolldown in Vite 8.

Why an upfront bundle delays readiness

A traditional Webpack development configuration starts from an entry such as src/index.tsx. It follows import and require references to build the module graph, runs Babel or TypeScript loaders, and writes chunks such as bundle.js and vendor.js to an in-memory file system. The dev server serves the result of that initial compilation.

flowchart LR
    subgraph WebpackDevServer["Webpack bundle-first development server"]
        Entry["Entry point"] --> Graph["Walk the module graph"]
        Graph --> Transform["Transpile TS and JSX"]
        Transform --> Bundle["Emit bundle.js in memory"]
        Bundle --> Ready["Server ready"]
    end

The server’s initial work grows with the modules it has to resolve, parse, transform, and emit. Build settings, cache state, and loader costs also matter. A large graph can delay readiness by tens of seconds, even if the first page needs only a fraction of those modules.

Measured development server startup times for Webpack 5 and Vite 6 Figure 1. Cold start for the measured project. Webpack 5 reached readiness in 14.24 seconds and Vite 6 in 184 milliseconds.

I use this number to compare where the two servers do their work. Startup measures readiness to accept HTTP requests. It does not include the cost of loading and rendering the first route, which is where Vite performs its first on-demand transforms.

Let the browser load the source graph

With <script type="module">, the browser can resolve module imports and request JavaScript modules separately. Vite serves an HTML entry that refers to the application entry point. The browser reads the entry, discovers the next imports, and fetches the dependencies it needs.

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- index.html -->
<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>

During startup, Vite initializes middleware and plugins and opens its port. A request for /src/main.tsx then reaches Vite’s Connect-based development middleware. In the Vite 6 setup, esbuild transpiles that file to JavaScript and Vite’s transforms rewrite imports into URLs the browser can resolve. The browser then requests source such as App.tsx as it discovers the corresponding imports.

flowchart TD
    subgraph ViteArchitecture["Vite native ESM development server"]
        Browser["Browser module loader"]
        Server["Vite dev server (Connect)"]
        Esbuild["esbuild Transformer"]
        Server -->|"1. Server ready (~180 ms here)"| Browser
        Browser -->|"2. HTTP GET /src/main.tsx"| Server
        Server -->|"3. Transform the requested file"| Esbuild
        Esbuild -->|"4. Return the transformed module"| Server
        Server -->|"5. 200 OK (ESM Response)"| Browser
        Browser -->|"6. Parse imports and request App.tsx"| Server
    end

An unvisited route behind a dynamic import can stay untransformed until the browser navigates to it. A statically imported route can still be part of the first load. Startup also includes any dependency discovery, configuration, and plugin work that the project requires.

Watch HTTP caching split source from dependencies

The browser Network panel shows individual source modules during the first request and conditional requests on later visits. I inspect the request headers and the URLs to see which cache path applied.

Vite development logs with ESM module requests and conditional HTTP responses Figure 2. Individual ESM module requests and HTTP 304 responses in the Vite development server log.

  • Application source is revalidated. The server can return an ETag. If the browser sends the same value in If-None-Match and the module is still current, Vite can answer 304 Not Modified without sending the body again.
  • Optimized dependencies are comparatively stable. Vite serves versioned URLs with Cache-Control: max-age=31536000, immutable. A new version query gives the browser a new cache key when the optimized dependency changes.

These policies help distinguish a genuine transform delay from a browser cache miss. When comparing startup or module graphs, record whether the dependency and browser caches were warm.

Trace a hot update to its accepting boundary

Vite tracks the modules served to the browser. On a file change, it invalidates the affected module and walks importer relationships to find an HMR boundary. It sends an update message over the development WebSocket when a boundary accepts the change.

1
2
3
4
5
6
7
8
9
10
11
12
// Example Vite HMR WebSocket payload
{
  type: 'update',
  updates: [
    {
      type: 'js-update',
      path: '/src/components/Header.tsx',
      acceptedPath: '/src/components/Header.tsx',
      timestamp: 1722654000123
    }
  ]
}

The client fetches the updated module with a timestamp query such as Header.tsx?t=1722654000123 to avoid reusing an older response. A small accepted update stays localized. Changes that reach several importers can affect more modules, and if no boundary accepts the update Vite can reload the page. The time depends on the affected part of the graph and the transforms involved.

Compare the development choices and production build

ConcernWebpack development serverVite development server
Initial workResolve and compile the initial bundle graphSet up the server and transform application source on request
Runtime modulesBundler runtime that can load generated chunksBrowser native ESM with rewritten import URLs
Transpilation in this comparisonBabel or ts-loaderesbuild in Vite 6
Update scopeBundler recompiles affected modules and emits a hot updateInvalidate modules and propagate through ESM importer boundaries
Production outputWebpack bundlesRollup in Vite 5–7, Rolldown in Vite 8

For a development comparison, I measure cold readiness, first-route load, and an edit within a known HMR boundary separately. Those numbers show what moving transforms onto the request path saves and what it defers.

There are still npm packages that ship CommonJS and ESM packages split across hundreds of files. The dependency pre-bundling and cache guide shows how Vite handles those dependencies before the browser loads them.

Next Generation Frontend Tooling
This post is licensed under CC BY 4.0 by the author.