I have below Angular Service Worker config file, which seems to be working fine for the api requests and static contents, but for the navigation urls it's not hitting the cache. For example if I open, www.mydomain.com
or www.mydomain.com/section
or www.mydomain.com/account/section
, the request goes to the server instead of being resolved locally, as a result the offline version of the app doesn't work.
{
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"updateMode": "prefetch",
"resources": {
"files": [
"/index.html",
"/manifest.json",
"/favicon.ico",
"/*.css",
"/runtime-es2015*.js",
"/polyfills-es2015*.js",
"/main-es2015*.js",
"/common-es2015*.js",
"/content/images/header-pattern.png",
"/content/fonts/roboto-v20-latin-regular.woff2",
"/content/fonts/raleway-v14-latin-regular.woff2",
"/content/fonts/material-icons.woff2",
"/content/images/logo-round-toolbar.png",
"/content/images/facebook.png",
"/content/images/linkedin.png",
"/content/images/twitter.png"
]
}
},
{
"name": "app-lazy-assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/*.js",
"/content/**"
],
"urls": [
"https://cdnjs.cloudflare.com/**",
"https://fonts.googleapis.com/**",
"https://fonts.gstatic.com/**"
]
}
}
],
"dataGroups": [
{
"name": "my-api-30days",
"urls": [
"/api/url/part/*",
"/api/url/*",
"/api/url/segment/*"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 300,
"maxAge": "30d"
}
},
{
"name": "my-api-5days",
"urls": [
"/api/account/5dayscacheurl"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 300,
"maxAge": "5d"
}
}
],
"navigationUrls": [
"/**",
"!/**/*.*",
"!/**/*__*",
"!/**/*__*/**",
"!/bypass/service/worker",
"!/account/bypass-service-worker**",
"!/bypass-service-worker**"
]
}
Can anyone please guide if I am missing something?
I have also gone through @angular/service-worker not working when offline but it seems that the answer doesn't apply to the latest version of Angular.