I have an Angular 11 app that I'm building for deployment in production with the following commands:
npm install
npm run build -- --prod --outputHashing=all
The problem I am having is that, once deployed, when I go the app's URL with my browser, I still see an older version of the application.
I initially thought this was a cache issue, even though I was compiling with the --outputHashing=all
option (it seems to be working from what I can tell, the output files in the dist
folder have seemingly random filenames). And it seemed to be the case: if I refresh the page after disabling the cache in Chrome's dev options it now shows the updated app.
However, here is the problem: if I close the browser and open it again... I go back to seeing the old app! So, clearing the cache seems to somehow be a temporary solution.
After further investigation, my suspicion is that it has something to do with angular's service workers
, since when I load the page with Chrome's dev tools open I can see a lot of network calls are marked as Served from service worker
.
However, I'm not enough of an expert in Angular to know how to diagnose further. I've read the documentation about service workers on angular's website, but it didn't help me in figuring out where the problem lies exactly. Can anyone point me in the right direction? Here is my service worker config file, it was automatically generated when the application was created. Let me know if there are other files I should provide:
{
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/manifest.webmanifest",
"/*.css",
"/*.js"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
]
}
If it makes any difference, the app is hosted inside a .NET Core service running the embedded Katana webserver, but it don't see how that would make any difference, it's just serving the files without further manipulation.