1

I have a PWA that needs to download map data before going offline. I have created a data group to cache those resources with the NGSW, and I have created an initialization process to fetch all data that will be required when offline. The dataGroup definition is as follows

{
  "name": "map",
  "urls": ["/map-api/**"],
  "cacheConfig": {
    "maxSize": 10000,
    "maxAge": "365d"
  }
}

thus the cache named ngsw:/:1:data:dynamic:map:cache is used. I have noticed, however, that whenever I update the app, the cache is deleted and then recreated.

I am not entirely sure why this happens (could be the browser clearing up space), I have not found any traces of this documented, but I have found two functions in the NGSW code that can do that. Is there a way to prevent this from happening? Is it behavior by design?

IAfanasov
  • 4,775
  • 3
  • 27
  • 42
Hodossy Szabolcs
  • 1,598
  • 3
  • 18
  • 34
  • This shouldn't happen afaict. Can you create and share a minimal reproduction that demonstrates the issue? (For example, a repo we can check out and run.) – gkalpak Aug 24 '21 at 12:16
  • That is pretty hard to do unfortunately, I need two versions of the app, with a populated cache, hosted on a trusted domain... I will try to create a replication, I am just a bit lost on how to do that – Hodossy Szabolcs Aug 24 '21 at 13:05
  • If this happens on localhost as well, you could create a simple app using Angular CLI + Angular ServiceWorker and push it to a GitHub repo (along with instructions on the steps one needs to follow to reproduce the issue). – gkalpak Aug 24 '21 at 18:54
  • I could not reproduce this on localhost unfortunately. – Hodossy Szabolcs Aug 26 '21 at 07:48
  • Now I have an observation that it only happens on Mobile. Maybe one step closer to a repro... – Hodossy Szabolcs Sep 21 '21 at 12:08

0 Answers0