🚀 Optimize your Vite app's speed by warming up Vite's transform cache during server idle periods.
Vite comes with a awesome built-in feature for warming up the cache, as outlined in Warm Up Frequently Used Files and vite-plugin-warmup.
However, when we want to warm up resources for lazily loaded pages, the fact that Vite's transform cache is generated during server startup can lead to longer initial page load times.
vite-plugin-idle-warmup
is a Vite plugin that optimizes server response times by warming up Vite's transform cache during server idle periods. It helps to enhance the user experience by reducing the loading times for subsequent requests.
Example project: playground
Install vite-plugin-idle-warmup
:
npm i -D vite-plugin-idle-warmup
Use the Vite plugin:
// vite.config.js
import { defineConfig } from 'vite';
import idleWarmup from 'vite-plugin-idle-warmup';
export default defineConfig({
plugins: [
idleWarmup({
files: ['./src/foo.ts', './src/BarComp.vue'],
}),
],
});
The files can be direct file names or glob patterns using fast-glob.