feat(pwa): add service worker registration

This commit is contained in:
Julien Oculi 2024-06-06 16:35:55 +02:00
parent 1e2630988f
commit c2477e0ff5
2 changed files with 9 additions and 0 deletions

View file

@ -0,0 +1,7 @@
export default function RegisterServiceWorker({ href }: { href: string }) {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register(href)
}
return <></>
}

View file

@ -2,6 +2,7 @@ import { asset, Head, Partial } from '$fresh/runtime.ts'
import { type PageProps } from '$fresh/server.ts'
import { Footer } from '../components/Footer.tsx'
import { Header } from '../components/Header.tsx'
import RegisterServiceWorker from '../islands/RegisterServiceWorker.tsx'
export default function App({ Component }: PageProps) {
return (
@ -52,6 +53,7 @@ export default function App({ Component }: PageProps) {
<Component />
</Partial>
</main>
<RegisterServiceWorker href={asset('/sw.js')} />
<Footer />
</body>
</html>