Browse Source

🐛 fix: repalce deprecated api : window.location.reload (#9040)

* 🐛 fix: repalce deprecated api : window.location.reload

* fix test
pull/9104/head
陈帅 5 years ago
committed by GitHub
parent
commit
98e7a56822
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      src/global.tsx

28
src/global.tsx

@ -5,6 +5,20 @@ import defaultSettings from '../config/defaultSettings';
const { pwa } = defaultSettings;
const isHttps = document.location.protocol === 'https:';
const clearCache = () => {
// remove all caches
if (window.caches) {
caches
.keys()
.then((keys) => {
keys.forEach((key) => {
caches.delete(key);
});
})
.catch((e) => console.log(e));
}
};
// if pwa is true
if (pwa) {
// Notify user if offline now
@ -34,8 +48,9 @@ if (pwa) {
};
worker.postMessage({ type: 'skip-waiting' }, [channel.port2]);
});
// Refresh current page to use the updated HTML and other assets after SW has skiped waiting
window.location.reload(true);
clearCache();
window.location.reload();
return true;
};
const key = `open${Date.now()}`;
@ -72,12 +87,5 @@ if (pwa) {
if (sw) sw.unregister();
});
// remove all caches
if (window.caches && window.caches.keys()) {
caches.keys().then((keys) => {
keys.forEach((key) => {
caches.delete(key);
});
});
}
clearCache();
}

Loading…
Cancel
Save