When we have a new build in our react project, users who work with our PWA because they have old cache they cant have our last changes and they have to remove their cache by press ctrl+F5 to reload again and then our changes work so we try to find the best solution to solve the problem.
I want to remove the cache for all users after the new build from the react projects.
finally I solved this problem for my projects.
I define a variable in local storage for versioning and I saved the project version after build and checked the version in the first react file ( componentDidMount()
in Routes.js
for example ) if they didn't match run the code below :
window.location.reload(true);
example :
componentDidMount(){
let name = 'Project-Name'
let version = '1.0.0'
console.log(`${name} v${version} 😎`)
const last_version = localStorage.getItem(`${name}-Version`)
if(last_version !== version){
console.log('New Version Available ! 😝')
localStorage.setItem(`${name}-Version`, version)
window.location.reload(true);
}
}