Skip to content

Commit f112b95

Browse files
feat(runtime): add main-thread boot script with SW registration
- Register rawscript-sw.js as a module-type Service Worker - Auto-reload page on first SW activation for fetch interception - Guard registration behind serviceWorker feature detection - Mark SW path as configurable for v0.9.0 (data-sw-path attr)
1 parent ce743ac commit f112b95

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/runtime/src/boot.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// TODO v0.9.0: make this configurable via data-sw-path attribute
2+
const SW_PATH = '/rawscript-sw.js'
3+
4+
if ('serviceWorker' in navigator) {
5+
navigator.serviceWorker.register(SW_PATH, { type: 'module' }).then((reg) => {
6+
if (reg.installing) {
7+
reg.installing.addEventListener('statechange', (e) => {
8+
if ((e.target as ServiceWorker).state === 'activated') {
9+
location.reload()
10+
}
11+
})
12+
}
13+
})
14+
}

0 commit comments

Comments
 (0)