Fixing ServiceWorker Clear Cache

This commit is contained in:
Fabian 2019-07-02 20:02:47 +02:00
parent ae5257b2b3
commit b05e2d3c55
2 changed files with 4 additions and 15 deletions

View File

@ -27,20 +27,9 @@ self.addEventListener('activate', (event) => {
});
self.addEventListener('message', (event) => {
if (event.data === "clear_cache") {
log("Clearing cache");
caches.delete(CACHE);
event.waitUntil(precache());
}
if (event.data === "update_index") {
log("Updating index");
event.waitUntil(caches.open(CACHE).then((cache) => {
return cache.addAll(["/", "/index.html"]).then(() => {
event.ports[0].postMessage("reload");
});
}))
}
log("Clearing cache");
caches.delete(CACHE);
event.waitUntil(precache());
});
var Types;

View File

@ -30,7 +30,7 @@ export default class SettingsPage extends Page<{ state: any }, { vault: string }
</select>
</div>
{/* <button class="btn" onClick={() => Theme.toggle()}>Toggle Dark Mode</button> */}
<button class="btn" onClick={() => window.navigator.serviceWorker.controller.postMessage("clear_cache")}>Clear cache</button>
<button class="btn" onClick={() => window.navigator.serviceWorker.controller.postMessage("message")}>Clear cache</button>
</div>
</div >;
}