From c93d379f204fc3839782f7d049afe5b9785532f4 Mon Sep 17 00:00:00 2001
From: Nicolas Lepage <19571875+nlepage@users.noreply.github.com>
Date: Wed, 16 Oct 2024 13:24:03 +0200
Subject: [PATCH] feat: improves examples
---
docs/hello-sse/index.html | 47 ++++++++++++++++++++++++--------
docs/hello-sse/sw.js | 8 ++++--
docs/hello-state-keepalive/sw.js | 8 ++++--
docs/hello-state/sw.js | 7 +++--
docs/hello/sw.js | 6 ++--
5 files changed, 54 insertions(+), 22 deletions(-)
diff --git a/docs/hello-sse/index.html b/docs/hello-sse/index.html
index c81fb1a..f0831d5 100644
--- a/docs/hello-sse/index.html
+++ b/docs/hello-sse/index.html
@@ -1,32 +1,57 @@
- go-wasm-http-server hello demo
+ go-wasm-http-server hello sse demo
-
+
+
+
+
+
+
+
+
diff --git a/docs/hello-sse/sw.js b/docs/hello-sse/sw.js
index 02dc53f..6fc9e46 100644
--- a/docs/hello-sse/sw.js
+++ b/docs/hello-sse/sw.js
@@ -1,12 +1,14 @@
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.23.1/misc/wasm/wasm_exec.js')
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v2.0.2/sw.js')
+const wasm = 'api.wasm'
+
addEventListener('install', (event) => {
- event.waitUntil(skipWaiting())
+ event.waitUntil(caches.open('examples').then((cache) => cache.add(wasm)))
})
-addEventListener('activate', event => {
+addEventListener('activate', (event) => {
event.waitUntil(clients.claim())
})
-registerWasmHTTPListener('api.wasm', { base: 'api' })
+registerWasmHTTPListener(wasm, { base: 'api' })
diff --git a/docs/hello-state-keepalive/sw.js b/docs/hello-state-keepalive/sw.js
index 3f8364f..4d8e820 100644
--- a/docs/hello-state-keepalive/sw.js
+++ b/docs/hello-state-keepalive/sw.js
@@ -1,8 +1,10 @@
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.23.1/misc/wasm/wasm_exec.js')
-importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v2.0.2/sw.js')
+importScripts('../sw.js')
+
+const wasm = '../hello-state/api.wasm'
addEventListener('install', event => {
- event.waitUntil(caches.open('hello-state').then((cache) => cache.add('api.wasm')))
+ event.waitUntil(caches.open('hello-state').then((cache) => cache.add(wasm)))
})
addEventListener('activate', event => {
@@ -11,4 +13,4 @@ addEventListener('activate', event => {
addEventListener('message', () => {})
-registerWasmHTTPListener('../hello-state/api.wasm', { base: 'api' })
+registerWasmHTTPListener(wasm, { base: 'api' })
diff --git a/docs/hello-state/sw.js b/docs/hello-state/sw.js
index fed8461..2f50ace 100644
--- a/docs/hello-state/sw.js
+++ b/docs/hello-state/sw.js
@@ -1,13 +1,14 @@
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.23.1/misc/wasm/wasm_exec.js')
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v2.0.2/sw.js')
+const wasm = 'api.wasm'
+
addEventListener('install', (event) => {
- event.waitUntil(caches.open('hello-state').then((cache) => cache.add('api.wasm')))
- event.waitUntil(skipWaiting())
+ event.waitUntil(caches.open('examples').then((cache) => cache.add(wasm)))
})
addEventListener('activate', (event) => {
event.waitUntil(clients.claim())
})
-registerWasmHTTPListener('api.wasm', { base: 'api' })
+registerWasmHTTPListener(wasm, { base: 'api' })
diff --git a/docs/hello/sw.js b/docs/hello/sw.js
index 0c1a3da..6fc9e46 100644
--- a/docs/hello/sw.js
+++ b/docs/hello/sw.js
@@ -1,12 +1,14 @@
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.23.1/misc/wasm/wasm_exec.js')
importScripts('https://cdn.jsdelivr.net/gh/nlepage/go-wasm-http-server@v2.0.2/sw.js')
+const wasm = 'api.wasm'
+
addEventListener('install', (event) => {
- event.waitUntil(caches.open('hello').then((cache) => cache.add('api.wasm')))
+ event.waitUntil(caches.open('examples').then((cache) => cache.add(wasm)))
})
addEventListener('activate', (event) => {
event.waitUntil(clients.claim())
})
-registerWasmHTTPListener('api.wasm', { base: 'api' })
+registerWasmHTTPListener(wasm, { base: 'api' })