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

Member

by brandy , in category: Javascript , 9 months ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by edmond_brakus , 9 months ago

@brandy 

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:
1
import { myModule } from './myModule.js?v=' + Date.now();


  1. Replace myModule.js with the actual path of the module you want to import.
  2. Date.now() 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.