What is the difference between Push API and Server Sent Events?

10,950

Solution 1

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.

Solution 2

You use Server Sent Events to connect directly to your website, it's fairly easy.

Web Push technology is much more complicated, a user's browser maintains one connection to the browser vendor's push server, which collects and delivers all pushes from websites (multiplexes them). Since the messages go through the third-party server, they should be encrypted. To use the Push API you (on the client side) get a browser-specific vendor's endpoint URL, generate a public encryption key, and send it back to your server for use. Then on your server when you want to push, you encrypt the message using the key and push it to the endpoint.

General info on Web Push

Firefox maintains an active connection to a push service in order to receive push messages as long as it is open.

This is the main advantage of Web Push - you can deliver the notifications just as user opens the browser, he won't have to visit your site. The disadvantage is that you'll need to get a permission from user for this subscription. Another disadvantage is that it's far from being widely supported currently.

Technical info on Push API

Share:
10,950
Rishul Matta
Author by

Rishul Matta

Updated on June 27, 2022

Comments

  • Rishul Matta
    Rishul Matta almost 2 years

    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?