I'm working on an Angular 5 project and want to provide PWA functionality with the @angular/service-worker package.
I can't manage to cache and serve Google Maps API requests (e.g. tiles). The responses aren't cached when online, therefore also not served when offline.
What I tried:
Adding Maps URL to dataGroups: No Error, but also no cache, when going offline I get the following Errors:
ERROR Error: Uncaught (in promise): Event: {"isTrusted":true} (in the main.bundle.js)
Adding Maps URL to assetGroups installMode: prefetch, where I get cross-origin errors when trying to prefetch:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Adding Maps URL to assetGroups installMode: lazy, where I get the same result as installMode: prefetch
The rest of the data caches and serves well (static from localhost & json from localhost API endpoint on a different port).
My ngsw-config.json looks like this: Any pointers are highly appreciated.
{
"index": "/index.html",
"assetGroups": [{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.png",
"/index.html"
],
"versionedFiles": [
"/*.bundle.css",
"/*.bundle.js",
"/*.chunk.js"
],
"urls": [
"https://fonts.googleapis.com/css?family=Roboto:300,400,500,700",
"https://fonts.gstatic.com/s/roboto/v18/KFOlCnqEu92Fr1MmEU9fBBc4AMP6lQ.woff2",
"https://fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2"
]
}
}, {
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**"
]
}
}],
"dataGroups": [{
"name": "from-api",
"urls": [
"/api/restaurants",
"/img/**",
"/icons/**",
"https://maps.googleapis.com/maps/**"
],
"cacheConfig": {
"maxSize": 100,
"maxAge": "1d",
"timeout?": "3s"
}
}]
}
Happy to provide more information if needed.
No caching or storage. You will not pre-fetch, cache, index, or store any Content to be used outside the Service, except that you may store limited amounts of Content solely for the purpose of improving the performance of your Maps API Implementation due to network latency (and not for the purpose of preventing Google from accurately tracking usage)...Feature request for offline maps: issuetracker.google.com/issues/35827808 - xomena