Long-polling vs websocket when expecting one-time response from server-side

前端 未结 2 1946
醉话见心
醉话见心 2021-01-01 01:44

I have read many articles on real-time push notifications. And the resume is that websocket is generally the preferred technique as long as you are not concerned about 100%

2条回答
  •  佛祖请我去吃肉
    2021-01-01 02:51

    There is an alterternative that don't require polling or having an open socket connection all the time.

    It's called web push.

    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. This lets developers deliver asynchronous notifications and updates to users that opt in, resulting in better engagement with timely new content.

    Some perks are

    • You need to ask for notification permission
    • Your site needs to have a service worker running in foreground
    • having a service worker also means you need to have SSL / HTTPS

提交回复
热议问题