Note:
- Explanation is based on the frontend made with React.js, but you can easily replicate it for other frameworks.
- Check out the working frontend demo here & codebase here.
Add this push-notification-SW.js file to your public folder.
Also, add these variables to your .env file:
REACT_APP_PUBLIC_VAPID_KEY=BGBUgRmq_y5sm7NJdEJNQiho94QUv8VeUEJ57CXehZ7ybxKNFWAjHx2p_WgUz_sQB7XBGcEOLv2iJ5V3lMCWUtg
REACT_APP_SERVER_URL=https://web-push-notifications-server.vercel.app/api
REACT_APP_OWNER_ID=<your-owner-id-here>
(Use the above REACT_APP_PUBLIC_VAPID_KEY & REACT_APP_SERVER_URL values only)