@jakobmelchard/web
v0.1.2
Published
Shared PWA shell: tokens, base CSS, manifest, service worker, install page
Readme
web
Shared PWA shell for the org's apps: design tokens, base CSS, manifest, service worker and install page. Published as @jakobmelchard/web.
npm install
npm run build # regenerate dist/ (commit the result)
npm run check # typecheck, rebuild, fail if dist/ changed
npm test
npm run e2e # Chromium; set CHROMIUM_PATH to use an installed one
go test ./...| Path | Contents |
|---|---|
| tokens/tokens.json | source of all design tokens |
| tokens/build_tokens.py | generates dist/tokens.* from it |
| src/ | base CSS, theme follower, manifest template, service worker, register, update check, write queue, install page |
| dist/ | committed build output: the npm package and the Go embed |
| embed.go | web.FS and web.Manifest for Go servers |
| test/vectors/ | manifest cases run by both the JS and the Go test |
Service worker
// /sw.js
self.WEB_SW = {
cache: 'app',
shell: ['/', '/static/app.js', '/static/style.css'],
network: { timeoutMs: 4000 },
offlinePage: '/',
}
importScripts('/web/sw.js')import { register } from '@jakobmelchard/web/register.js'
import { watchUpdates } from '@jakobmelchard/web/update.js'
register({ version: shellVersion })
watchUpdates({ url: '/version', onUpdate: () => showReloadNotice() })offlinePage must be one of the shell entries. Responses served without the network carry X-Offline: 1.
Offline writes
import { createQueue } from '@jakobmelchard/web/queue.js'
const queue = await createQueue({
send: (op) => fetch('/api/save', { method: 'POST', body: JSON.stringify(op) }),
onDrop: (op, res) => reportRefused(op, res.status),
})
await queue.push({ id: 1 })send throws when the network is down; that, an X-Offline: 1 response and a 408, 429, 502, 503 or 504 keep the op queued. Any other failed response drops the op and calls onDrop. Open tabs share one queue through Web Locks. Pass store: { get, set } to replace IndexedDB/localStorage.
Go
go get github.com/JakobMelchard/[email protected]