Skip to content

Datagroups defined in service worker config are purged when app is updated #20785

Closed

Description

@atsjo

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

When publishing a new version of an app with a service worker, the datagroups are purged together with the old assets cached, even if the version of the datagroup is the same.

Expected behavior

Cached responses in datagroups are kept, unleless datagroup version is changed.

Minimal reproduction of the problem with instructions

  • Create app with service worker (can use the current cli 1.5.5): ng new testapp --service-worker
  • Use cli 1.6 rc in package.json to support building service worker
  • Add a datagroup to cache api respones, and cache data
  • make a new build and publish this, then observe in devtools how the cache and metadata for the datagroup are purged when app is updated (the caches are deleted, not only the content)

What is the motivation / use case for changing the behavior?

From what I could read in the docs, the expected behaviour is how this functionality is supposed to work. For small api respones the current behaviour is not a big problem, but when caching lots of media files for offline playback, it is...

Environment


Angular version: 5.0.0 - 5.1.0-rc.1


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [x] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [x] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Activity

  1. added
    area: service-worker
    on Dec 5, 2017
  2. added this to the Backlog milestone on Jan 23, 2018
  3. modified the milestones: Backlog, needsTriage on Feb 26, 2018
  4. mfowler001 commented on Aug 22, 2019

    @mfowler001

    We are using the Angular Service Worker implementation to cache videos for offline viewing, and we expect that many of our users will be downloading the videos over slow connections. They will not thank us for wiping their downloaded videos every time we update the application!

    It would be really useful to add a note to the official documentation explaining the current behaviour. The reason for the disappearing videos was not immediately apparent to us, as the cleanup is not triggered until the old version has no clients (normally when the browser is closed).

    It would also be useful to describe a possible workaround. The best we can think of would be to remove the following line in ngsw-worker.js:
    yield Promise.all(this.dataGroups.map(group => group.cleanup()));
    This would obviously mean that datagroup caches are never purged. However, this would be the better choice in our scenario. Any alternative suggestions would be very welcome.

  5. added
    feature
    open for contributions
    and removed
    feature
    on May 25, 2020
  6. gkalpak commented on May 25, 2020

    @gkalpak
    Member

    For future reference:
    While the current behavior is not necessarily wrong, this is indeed an area that the ServiceWorker could improve on: Keeping previously cached data as long as the data-group version remains the same (and subject to the rest of the data-group config, such as max age, max size, etc.).

  7. matt-potts-autodesk commented on Aug 25, 2020

    @matt-potts-autodesk

    I am experiencing the same issue with the Angular Service Worker, this is a great feature but clearing the data groups each time the application is updated is a real problem. Is there any ETA for when this will be addressed? TIA

  8. gkalpak commented on Aug 25, 2020

    @gkalpak
    Member

    There is no specific timeline at this point, I am afraid. If anyone wants to work on it, I would be happy to review, though 😉

    BTW, for static assets (such as videos) it might be better to use asset-groups instead of data-groups. Data groups are better suited for dynamically generated responses (such as retrieving data from a DB, etc.).

  9. matt-potts-autodesk commented on Aug 27, 2020

    @matt-potts-autodesk

    Thanks I'll take a look and see about making a PR for it, can you possibly point me to the location of SW code?

    We are using the data groups to cache long lived api responses so we would like that data to stay around even if the app has been updated and rely on the maxAge we have set in our ngsw-config.json file.

  10. added
    P3
    and removed on Oct 1, 2020
  11. gkalpak commented on Jul 5, 2021

    @gkalpak
    Member

    This should have been fixed by #42622.

  12. angular-automatic-lock-bot commented on Aug 5, 2021

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  13. locked and limited conversation to collaborators on Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: service-workerfreq3: highopen for contributionsstate: confirmedtype: bug/fix

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions