Skip to content

Commit 9167013

Browse files
author
pooya parsa
committed
feat: cleanupOutdatedCaches
1 parent 16c4d84 commit 9167013

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

docs/modules/workbox.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Workbox takes a lot of the heavy lifting out of precaching by simplifying the AP
8989

9090
(String) Loads and inserts the contents of the specified file path into the service worker script, below autogenerated calls to `workbox.precaching.*`. You may add as many extra calls as you want to this file.
9191

92+
### `cleanupOutdatedCaches`
93+
94+
(Boolean) Find and remove any of the older precaches that might have been used by previous versions of Workbox.
95+
9296
<!-- Offline -->
9397

9498
### `offline`

packages/workbox/lib/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
revision: undefined
2222
},
2323
cachingExtensions: [],
24+
cleanupOutdatedCaches: true,
2425

2526
// Offline
2627
offline: true,

packages/workbox/templates/sw.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ workbox.core.clientsClaim()
1919
workbox.core.skipWaiting()
2020
<% } %>
2121

22+
<% if (options.cleanupOutdatedCaches) { %>
23+
workbox.precaching.cleanupOutdatedCaches()
24+
<% } %>
25+
2226
<% if (options.offlineAnalytics) { %>
2327
// Enable offline Google Analytics tracking
2428
workbox.googleAnalytics.initialize()

test/__snapshots__/pwa.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ workbox.core.clientsClaim()
7070
// Skip over the SW waiting lifecycle stage
7171
workbox.core.skipWaiting()
7272
73+
workbox.precaching.cleanupOutdatedCaches()
74+
7375
// Enable offline Google Analytics tracking
7476
workbox.googleAnalytics.initialize()
7577

0 commit comments

Comments
 (0)