Skip to content

@angular/pwa doesn't clean up previous service worker version's cached content #41728

@rustygreen

Description

@rustygreen

🐞 bug report

Affected Package

The issue is caused by package @angular/pwa

Is this a regression?

No

Description

I am noticing that with every new version of my application the cache size grows considerably because the Angular Service worker is keeping the previous versions of the application in cache? This means that everytime you release a new version of your application, the new version's resources will be cached for offline use (the expected behavior). However, all of the cached content (scripts, css, HTML, etc) from the previous versions of the application are still stored in cache. This means that the application's cache will grow exponentially with every release of your application.

🔬 Minimal Reproduction

  1. Setup new CLI project ng new my-pwa-app
  2. Add PWA support ng add @angular/pwa --project my-pwa-app
  3. Build production version of application and run locally (observe cache size)
  4. Make small (non-functional) change to the application (just to change file hashing) - representing a new version of your application being deployed.
  5. Build production version of the application and run locally again (NOTE: the cache size will be double what it was before). Repeat steps 4 and 5 and this behavior will continue (cache size will continue to grow, because it is holding onto the previous version's cached files).

Application cache storage (same content, different version):
Version 1: 12.2 MB
Version 2: 23.5 MB
Version 3: 32.9 MB
...etc.

🌍 Your Environment

Angular Version: 11
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: service-workerIssues related to the @angular/service-worker package

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions