Vite's dev server starts fast because it doesn't transform your code until the browser asks for it. (It does bundle your npm dependencies up front and caches them in node_modules/.vite, but your own files wait.)
The catch is the first time you open a big page. Vite might have to transform hundreds of files before the browser can show it, and you sit there waiting.
This is the cold-start problem.
server.warmup fixes this issue. You list the files you use the most, and Vite transforms them in the background as soon as the server starts, so they're ready by the time you open the page.
Choosing which files to warm up
Don't warm up everything in src/. Warmup runs in the background, so it won't slow down startup. But it burns CPU on files you may never open, and that work competes with the pages you actually load.
Pick the files you hit on almost every page load:
- Your entry point and app shell:
main.tsx, App.tsx, and layout pieces like the nav bar and sidebar.
- Your router: the file that defines your routes, like
src/router/index.ts.
- Heavy shared components: data tables, charts, rich-text editors, anything slow to transform.
- The page you reload all day: if everyone works on the dashboard, warm up the dashboard.
To find the slow files, run Vite with the transform log on:
npx vite --debug transform
Each line shows how long a file took. Look for the ones that stand out, especially near the top of your import tree.
You can also check the Network tab in your browser's dev tools. Filter by JS and look for files with a long "Waiting for server response" time. Leave "Disable cache" off while you do this, because it makes every reload slower than normal.
Setting up warmup
Add the files to server.warmup.clientFiles in your Vite config. You can use exact paths or glob patterns:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
server: {
warmup: {
clientFiles: [
// Entry point and app shell
'./src/main.tsx',
'./src/App.tsx',
'./src/components/layout/*.tsx',
// Router
'./src/router/**/*.{ts,tsx}',
// Heavy components used on many pages
'./src/components/ui/DataTable.tsx',
'./src/components/ui/RichEditor.tsx',
],
},
},
});
You can also add './index.html'. Vite treats it like a real page request and warms the scripts it loads.
What happens at startup
Vite transforms the files you listed, plus the files they import, in the background and caches the results. It doesn't wait for this to finish before printing the server URL. If you open the page right away, some files may still be in progress. Give it a few seconds and they'll be served straight from the cache.
Tip: starting the server with vite --open (or setting server.open) automatically warms your entry point, even with no warmup config.
Warming up SSR code
If you use server-side rendering (SvelteKit, Nuxt, Astro, or your own setup), Vite transforms the server code separately from the browser code. Warm it up with ssrFiles:
export default defineConfig({
server: {
warmup: {
clientFiles: ['./src/entry-client.tsx'],
ssrFiles: ['./src/entry-server.tsx'],
},
},
});
On Vite 6 and later, you can also set warmup for each environment with environments.<name>.dev.warmup.
Checking that it works
Run Vite with the transform log on:
npx vite --debug transform
With warmup on, log lines for your files show up right after startup and don't show up again when you open the page. Any file that appears after the page loads wasn't warmed, so it's a candidate to add.
In a big app with a deep import tree, warmup can make the first page load after a restart noticeably faster. In a small app you may not notice a difference. Either way, the server still starts fast.
Walt is a software engineer, startup founder and previous mentor for a coding bootcamp. He has been creating software for the past 20+ years.