feat: convert app to PWA with offline support and service worker
This commit is contained in:
22
components/providers/SWRegistration.tsx
Normal file
22
components/providers/SWRegistration.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function SWRegistration() {
|
||||
useEffect(() => {
|
||||
if ('serviceWorker' in navigator && process.env.NODE_ENV === 'production') {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker
|
||||
.register('/sw.js')
|
||||
.then((registration) => {
|
||||
console.log('SW registered:', registration);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('SW registration failed:', error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user