Currently, I am working on an ASP.Net Core App with Angular 8 for the front-end. However, I have encountered some issues with the cache when publishing a new version of my app. The DOM does not reflect the changes in the front end. To address this problem, I decided to install a service worker by using the following command:
ng add @angular/pwa@v8-lts
This installation process resulted in the creation of new files and modifications to existing ones as outlined below:
Modified Files:
- angular.json
- package-lock.json
- package.json
- index.html
- app.module
Created Files:
- manifest.webmanifest
- ngsw-config.json
I researched how to clean the cache, and it was suggested that I add the following code snippet to the service worker:
constructor(updates: SwUpdate) {
updates.available.subscribe(event => {
if (promptUser(event)) {
updates.activateUpdate().then(() => document.location.reload());
}
});
}
My question now is, where exactly should I insert this code snippet? Do I need to create a new file for it? How do I bind it to my app effectively?