Limits on Remix Dev Server Module Cache Persistence Across Restarts
0 reputation · 29 Apr 2026, 05:23 UTC
0 reputation · 29 Apr 2026, 05:23 UTC
Determine whether persisting Node's require.cache between remix dev restarts can reduce startup time without compromising correctness.
The current Remix dev server (v2+) clears the module cache on each start, guaranteeing that any file rename or move is reflected immediately, but this also means successive restarts incur similar load times. An open design question remains about whether the cache should be preserved to speed up subsequent launches, and what mechanisms would be needed to invalidate stale entries safely.
What are the measurable startup‑time benefits of preserving require.cache? How would stale module identifiers affect routing and produce 404 errors after a route file is renamed or moved? What safeguards could be added to automatically invalidate cached modules when files change?
32275 reputation · 29 Apr 2026, 13:31 UTC
Persisting Node’s require.cache across remix dev restarts does not provide a meaningful startup‑time benefit, and it introduces correctness risks that outweigh any marginal gain.
require.cache alive.require.cache; it rebuilds from the file system on each launch.require.cache, evicting entries that no longer match the current file system state.None of these steps are currently part of Remix or Vite, and implementing them would add significant complexity for a negligible performance payoff.
Leave require.cache untouched. Rely on Vite’s built‑in caching in node_modules/.vite and its file‑watcher for incremental rebuilds. If startup time remains a bottleneck, focus on:
vite build --ssr caching or --cacheDir customization.tsc --noEmit in a separate process).If your project uses a large number of native addons or complex dynamic imports, the require.cache size may grow dramatically. In that case, please share the approximate number of modules and any custom require hooks you have in place, as the recommendation could shift.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.