title: How to ensure Workbox cache update for updates that never activate
body: <p>I've been working on converting a web app we have to a PWA and I am using Google's Workbox (v3.6.1) for precaching resources.  For the most part it has been working well, but there appears to be a specific scenario that is causing the cached files to fall out of sync.</p>
  
  <p>I am using the basic <code>precacheAndRoute()</code> functionality to setup the files for precaching.</p>
  
  <pre><code>workbox.precaching.precacheAndRoute([]); //populated at build time via workbox-cli
  </code></pre>
  
  <p>On first install, and most updates, the files are getting precached as expected.  However, if a Service Worker instance is currently <code>waiting</code> and a new update gets installed, all of the pending files in the temp cache are getting deleted and don't get installed with the newest version.</p>
  
  <p>It seems that the install step of <code>workbox.precaching</code> updated the IndexDB that contains all of the file versions when it adds the files to the temp cache.  So the next Service Worker version believes that the prior latest version of all files are currently cached, even though they are still only in the temp cache.  Then the new install removes everything from the temp cache before inserting it's own files.  Thus the pending cached files for the previous <code>waiting</code> instance are lost forever.</p>
  
  <p>I had the idea that on install of a new version, I could force the temp cache to sync to the permanent cache (by using a <a href="https://developers.google.com/web/tools/workbox/reference-docs/latest/workbox.precaching.PrecacheController" rel="nofollow noreferrer">PrecacheController</a> and the <code>activate()</code> function) before allowing the new instance to precache, but I have some concerns about updating the permanent cache while the user is actively using the app.</p>
  
  <p>I'm looking for either confirmation that my idea here is an appropriate solution, or any other suggestions on how to handle this scenario.</p>