From the documentation I could figure out that Push API and Server Sent Events both are half duplex but why two different technologies for the same functionality? Is there something more significant in Push API?
Server sent events(SSE) is a pushing technology that enables pushing notification/message/events from the server to the client(s) via HTTP connection.
The Push API gives web applications the ability to receive messages pushed to them from a server, whether or not the web app is in the foreground, or even currently loaded, on a user agent.
A server-sent event is when a web page automatically gets updates from a server. This was also possible before, but the web page would have to ask if any updates were available. With server-sent events, the updates come automatically.
SSE is best used when it's not necessary to send data from client to server. For example, in status updates and push notification applications, the data flow is from the server to the client only. This is what SSE is designed for, so WebSocket would be overkill. It's always wise to use the best tool for the job.
The Push API allows the server to send a notification to a client even when your site is not open, because it relies on service workers.
SSE (or WebSockets) work as long as the user is using your site.
There are some examples (with documentation) in the Web Push
section of the ServiceWorker Cookbook that can help you understand this better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With