Skip to content

Commit 598e0a8

Browse files
committed
Ask server to respond with clear-site-data when pressing the reset cache button
1 parent b6367bd commit 598e0a8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/playground/index.ejs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,12 @@
157157
splashReset.onclick = function () {
158158
splashReset.disabled = true;
159159
function hardRefresh() {
160-
var search = location.search.replace(/[?&]nocache=\d+/, '');
161-
location.replace(location.pathname + search + (search ? '&' : '?') + 'nocache=' + Math.floor(Math.random() * 100000));
160+
var search = location.search.replace(/[?&]nocache=[\d.]+(?=$|&)/, '');
161+
// This is a functional cookie used so that we respond with Clear-Site-Data just once. No tracking.
162+
// Can't use nocache parameter to trigger this because people might accidentally bookmark that, and
163+
// then we would be clearing their cache on every visit.
164+
document.cookie = 'tw_clear_cache_once=1; max-age=60; path=/; samesite=strict; secure';
165+
location.replace(location.pathname + search + (search ? '&' : '?') + 'nocache=' + Math.floor(Math.random() * 10000000));
162166
}
163167
if ('serviceWorker' in navigator) {
164168
setTimeout(hardRefresh, 5000);

0 commit comments

Comments
 (0)