Skip to content

Commit 47035a9

Browse files
authored
fix: service-worker.js and qwik-prefetch-service-worker.js caches removal (#7782)
1 parent 4199268 commit 47035a9

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.changeset/small-rocks-relate.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@builder.io/qwik': patch
3+
'@builder.io/qwik-city': patch
4+
---
5+
6+
PATCH: Keeping the service worker components now also removes their associated Cache storage.

packages/qwik-city/src/runtime/src/sw-register.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010
}
1111
}
1212
});
13-
} else {
14-
// eslint-disable-next-line no-console
15-
console.log('Service worker not supported in this browser.');
13+
}
14+
if ('caches' in window) {
15+
caches
16+
.keys()
17+
.then((names) => {
18+
const cacheName = names.find((name) => name.startsWith('QwikBuild'));
19+
if (cacheName) {
20+
caches.delete(cacheName).catch(console.error);
21+
}
22+
})
23+
.catch(console.error);
1624
}
1725
})();

packages/qwik/src/core/components/prefetch.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ const PREFETCH_CODE = /*#__PURE__*/ ((
7474
});
7575
});
7676
}
77+
if ('caches' in window) {
78+
caches
79+
.keys()
80+
.then((names) => {
81+
const cacheName = names.find((name) => name.startsWith('QwikBundles'));
82+
if (cacheName) {
83+
caches.delete(cacheName).catch(console.error);
84+
}
85+
})
86+
.catch(console.error);
87+
}
7788
}).toString();
7889

7990
/**

0 commit comments

Comments
 (0)