How to force vite clearing cache in vue.js 3?


by brandy , in category: Javascript , a month ago

How to force vite clearing cache in vue.js 3?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by edmond_brakus , a month ago


In Vue.js 3, you can force Vite to clear the cache by adding a query parameter to the request when you import a module. Here's how you can do it:

  1. Import the module with a query parameter:
import { myModule } from './myModule.js?v=' +;

  1. Replace myModule.js with the actual path of the module you want to import.
  2. generates a timestamp that is always different, so it will force Vite to fetch the module again and ignore the cached version.

By adding a query parameter with a changing value to the import statement, Vite will treat it as a new dependency and fetch the module again, bypassing the cache.

Note: This should only be used during development, as it may impact the performance in a production environment.