This commit is contained in:
Nicolas Lepage
2019-12-02 16:52:40 +01:00
parent d983ee2221
commit b4be701615
4 changed files with 57 additions and 65 deletions

View File

@@ -20,22 +20,7 @@
<label for="name">Name : </label><input id="name" value="World">
<button onclick="hello()">Hello</button>
<script>
const startWasm = async (wasm, { scope, base = '' } = {}) => {
try {
const options = {}
if (scope) options.scope = scope
const registration = await navigator.serviceWorker.register('sw.js', options)
await navigator.serviceWorker.ready
registration.active.postMessage({
type: 'startWasm',
wasm,
base,
})
} catch (e) {
console.error(e)
}
}
startWasm('api.wasm')
wasmhttp.register('api.wasm', { base: 'api' })
</script>
</body>
</html>

View File

@@ -1,23 +0,0 @@
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.13.4/misc/wasm/wasm_exec.js')
addEventListener('install', (event) => {
console.log('install!')
// wasmhttp.serve({
// wasm: 'api.wasm',
// base: '/api',
// })
event.waitUntil(skipWaiting())
})
addEventListener('activate', event => {
console.log('activate!')
event.waitUntil(clients.claim())
})
addEventListener('fetch', () => {
console.log('fetch!')
})
addEventListener('message', ({ data }) => {
console.log('message', data)
})