In my Angular 8 project, I've integrated PWA, SSR and service workers.
When I run the project in local using this command: npm run build:ssr && npm run serve:ssr
, I face the following issues:
- API url, images are not cached. If I run in offline mode, they are not shown.
- Homepage loads fine. But when I navigate to any other page, it shows all HTTP calls as pending.
ngsw-config.json
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js"
]
}
}, {
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
],
"urls": [
"https://fonts.googleapis.com/**"
]
}
}
],
"dataGroups": [
{
"name": "api-performance",
"urls": [
"/api/siteInfo/home_carousel",
"/api/siteInfo/categories",
"/api/siteInfo/testimonials",
"/api/siteInfo/footer",
"/api/siteInfo/contact",
"/api/gallery/fetch",
"/api/offer/fetch",
"/api/offer/check",
"https://maps.gstatic.com/**"
],
"cacheConfig": {
"strategy": "performance",
"maxAge": "1h",
"maxSize": 100,
"timeout": "5s"
}
}
]
After build, this is the generated ngsw.json file content:
"dataGroups": [
{
"name": "api-performance",
"patterns": [
"\\/api\\/siteInfo\\/home_carousel",
"\\/api\\/siteInfo\\/categories",
"\\/api\\/siteInfo\\/testimonials",
"\\/api\\/siteInfo\\/footer",
"\\/api\\/siteInfo\\/contact",
"\\/api\\/gallery\\/fetch",
"\\/api\\/offer\\/fetch",
"\\/api\\/offer\\/check",
"https:\\/\\/maps\\.gstatic\\.com\\/.*"
],
"strategy": "performance",
"maxSize": 100,
"maxAge": 3600000,
"timeoutMs": 5000,
"version": 1
}
],
Note: There's nothing wrong with the testimonial or other url because when I do ng serve
all http calls are made correctly with 200 status.