2

Overview

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? Is it expected that the Angular Service worker schematic will add the code to clean up the cache from the previous versions? If not, the Angular PWA schematics don't seem scalable (maybe I'm just missing something)?

Steps to reproduce

  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).

Example

enter image description here

R. Richards
  • 24,603
  • 10
  • 64
  • 64
Rusty
  • 109
  • 1
  • 9

1 Answers1

0

The SW cleans its caches on SW restart (which won't happen if you have DevTools open). Go into the SW tab in DevTools, stop the worker, then start it, wait a few seconds, and check Cache Storage (be sure to right click and refresh it). The older caches should be gone.

Reference from below links.

https://github.com/angular/angular/issues/29985#issuecomment-484864815

https://github.com/angular/angular/issues/21044#issuecomment-352081302

ghost...
  • 975
  • 3
  • 16
  • 33