summaryrefslogtreecommitdiffstats
path: root/sw.js
diff options
context:
space:
mode:
Diffstat (limited to 'sw.js')
-rw-r--r--sw.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/sw.js b/sw.js
index f733ff6..3e38576 100644
--- a/sw.js
+++ b/sw.js
@@ -1,5 +1,5 @@
// Change version to cause cache refresh
-const static_cache_name = "site-static-v1.0.1";
+const static_cache_name = "site-static-v1.0.2";
// Got them with du -a and minor cleaning up
const assets = [
"/img/avatars/asijanec.png",
@@ -72,22 +72,29 @@ const assets = [
"/",
"/index.html",
"/login.html",
- "/logout.js"
+ "/logout.html"
];
importScripts("/js/lib/localforage.min.js");
self.addEventListener("install", (evt) => {
// Add localforage.clear() if storage purge is required
- evt.waitUntil(
- localforage.clear()
- );
-
- evt.waitUntil(
+ evt.waitUntil(async function () {
+ localforage.clear();
caches.open(static_cache_name).then((cache) => {
cache.addAll(assets);
- })
- );
+ });
+
+ if (!evt.clientId) return;
+ const client = await clients.get(event.clientId);
+
+ if (!client) return;
+
+ client.postMessage({
+ msg: "install"
+ });
+
+ });
});
// Delete old caches
@@ -106,4 +113,4 @@ self.addEventListener("fetch", (evt) => {
evt.respondWith(caches.match(evt.request).then((cache_res) => {
return cache_res || fetch(evt.request);
}))
-}); \ No newline at end of file
+});