
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
vite-plugin-cache
Advanced tools
Zero-config Vite plugin to add Workbox-based service worker with stale-while-revalidate caching.
A Vite plugin that auto-generates and registers a Workbox-based service worker to cache your API requests and static assets.
service worker using Workbox at build timestale-while-revalidatecache-firstnetwork-firstcache-onlynetwork-onlyExpirationPluginimageCache, pageCache, staticResourceCache, googleFontsCachenpm install vite-plugin-cache --save-dev
// vite.config.ts
import { defineConfig } from 'vite';
import { vitePluginCache } from './vite-plugin-cache';
export default defineConfig({
plugins: [vitePluginCache()],
});
This will use the default configuration:
GET requests to /api/* using stale-while-revalidateExpirationPlugin with 100 entries and 60 seconds ageindex.htmlYou can override the default caching rules with your own:
vitePluginCache({
config: {
'custom-api-cache': {
match: ({ url }) => url.pathname.startsWith('/v1/'),
strategy: 'network-first',
plugins: {
expiration: {
maxEntries: 50,
maxAgeSeconds: 120,
},
},
},
},
});
Workbox recipes simplify common patterns:
vitePluginCache({
recipies: {
imageCache: {},
googleFontsCache: {},
pageCache: null,
},
});
You can dynamically generate config:
vitePluginCache({
config: (defaultConfig) => ({
...defaultConfig,
'docs-cache': {
match: ({ url }) => url.pathname.startsWith('/docs/'),
strategy: 'cache-first',
},
}),
});
| Strategy | Description |
|---|---|
stale-while-revalidate | Returns cached response immediately, updates in background |
network-first | Tries network first, fallback to cache |
cache-first | Tries cache first, fallback to network |
network-only | Always fetches from network |
cache-only | Only uses the cache |
Currently supported:
expiration: Uses ExpirationPlugin to limit cache size and entry age.plugins: {
expiration: {
maxEntries: 200,
maxAgeSeconds: 3600,
},
}
The generated service worker will be placed in your build output (e.g., dist/vite-plugin-cache-service-worker.js) and automatically registered in the browser.
MIT
FAQs
Zero-config Vite plugin to add Workbox-based service worker with stale-while-revalidate caching.
We found that vite-plugin-cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.