mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
25 lines
697 B
Templ
25 lines
697 B
Templ
package state
|
|
|
|
var (
|
|
serviceWorkerHandle = templ.NewOnceHandle()
|
|
)
|
|
|
|
templ RegisterServiceWorker() {
|
|
@serviceWorkerHandle.Once() {
|
|
<script>
|
|
if ("serviceWorker" in navigator) {
|
|
window.addEventListener("load", function() {
|
|
navigator.serviceWorker
|
|
.register("/sw.js")
|
|
.then(function (registration) {
|
|
console.log("Service Worker registered with scope:", registration.scope);
|
|
})
|
|
.catch(function (error) {
|
|
console.log("Service Worker registration failed:", error);
|
|
});
|
|
});
|
|
}
|
|
</script>
|
|
}
|
|
}
|