1

What is an efficient way to have push notification in a web application?

I have a web application and I want it to be dynamically refreshed for every specific user by push notification instead of regularly pulling the data from the server.

Laurel
  • 5,965
  • 14
  • 31
  • 57
user3505838
  • 351
  • 3
  • 8

1 Answers1

2

The best one doesn't exist, but you have some options to get this done.

Web sockets (IMO, I recommend this approach)

The first one and the most efficient is to use web sockets in an HTML5 page. You could use a library in PHP to get this done, or you could use a Node.js server with Socket.io or similar to handle the frontend of your site (I see this a lot in online products).

Note: When using web sockets the client and the server will be sending each other a TTL (time-to-live) message, this is a really really small message with small headers just to keep the connection open and alive.

Short-polling

The second one is short polling, here you make an ajax request to the server every X seconds or minutes (depends on the frequency that you want to refresh the data). NOTE: this is the least efficient, because you're opening a lot of request to server just to check if there's new data

Long-polling

The third one is long polling, this one is like short polling but instead you keep a single connection opened for a longer period of time and get a response from the server when there's data to be sent to the client. This is less consuming, but you still keep on permanent connection open between the client and the server.

gpopoteur
  • 1,509
  • 10
  • 18