From 07a1e455a043c30597577b431c9e8253feee3636 Mon Sep 17 00:00:00 2001 From: familyfriendlymikey Date: Tue, 16 Aug 2022 02:34:04 -0400 Subject: [PATCH] update sw --- package.json | 2 +- sw.imba | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 4703e90..e188b0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fuzzyhome", - "version": "0.1.29", + "version": "0.1.32", "scripts": { "start": "imba run -SMH --baseurl . -w server.imba", "build-app": "rm -rf dist && imba build -SMH --baseurl . server.imba", diff --git a/sw.imba b/sw.imba index 782a1d8..abfe0ad 100644 --- a/sw.imba +++ b/sw.imba @@ -1,9 +1,9 @@ const app_name = "fuzzyhome" -let p = console.log import { version } from './package.json' const app_prefix = "{app_name}_cache" const cache_name = "sw-{app_prefix}-{version}" -p cache_name +let p = do |s| console.log "{cache_name} {s}" +p "loaded" let urls = [ './', @@ -13,31 +13,32 @@ let urls = [ ] self.addEventListener('fetch') do |e| - p "{cache_name} fetch" + p "fetch" def intercept request if request - p "{cache_name} responding with cache {e.request.url}" + p "responding with cache {e.request.url}" request else - p "{cache_name} not cached, fetching {e.request.url}" + p "not cached, fetching {e.request.url}" fetch e.request e.respondWith(caches.match(e.request.url).then(intercept)) self.addEventListener('install') do |e| - p "{cache_name} install" + p "install" def add_urls_to_cache cache - p "{cache_name} adding urls to cache" + p "adding urls to cache" cache.addAll urls skipWaiting! e.waitUntil(caches.open(cache_name).then(add_urls_to_cache)) self.addEventListener('activate') do |e| - p "{cache_name} activate" + p "activate" def delete_cached keys let temp = keys.map! do |key, i| - p "{cache_name} checking cache {key}" + p "checking cache {key}" if key !== cache_name - p "{cache_name} deleting cache {keys[i]}" - caches.delete key + p "deleting cache {key}" + let result = await caches.delete key + p "deletion of {key} result: {result}" Promise.all(temp) e.waitUntil(caches.keys().then(delete_cached))