Push API and Notification API Relationship
You'll learn: How the Push API and Notification API work together to deliver server-triggered notifications to users even when your web app isn't open.
Two APIs, One Goal
Think of these APIs like a relay race: the Push API is the first runner who receives the baton from your server, and the Notification API is the second runner who crosses the finish line by showing something to the user.
The Push API handles the server-to-client communication. It allows your backend to send messages to the service worker, even when the user has closed all tabs of your site. This is the "receiving" half of the equation.
The Notification API handles the client-side display. It creates the actual visual notification that users see on their device—complete with title, body text, icon, and actions. This is the "showing" half.
How They Collaborate
Here's the flow:
- User grants notification permission and subscribes to push notifications (Push API)
- Your server sends a push message to the browser's push service
- The browser receives the push and fires the
pushevent in your service worker - Your service worker handles the
pushevent and uses the Notification API to display a notification
The Push API gets the message to your service worker; the Notification API makes it visible. You can't show a push notification without both: the Push API doesn't display anything on its own, and the Notification API alone can't receive server messages.
Why This Design?
This separation keeps concerns clear: networking/messaging vs UI presentation. Your service worker can receive push data and decide whether to show a notification, what to show, or perform background work instead.
Key Takeaway: The Push API receives server messages in the service worker, while the Notification API displays them to users—together they enable complete server-to-user communication.