How to make all connected browsers reload initiated by a server-side event

前端 未结 7 1408
忘掉有多难
忘掉有多难 2020-12-19 17:42

Suppose there is a webpage with dynamically generated content -- say a div containing the current number of connected browsers. When the count changes on the server I want a

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 18:00

    As of Dec 2014, there is a W3C proposed recommendation called Server Sent Events (SSE) that would allow you to do that over HTTP: http://www.w3.org/TR/eventsource

    It seems that it is a standardization of a group of techniques known as Comet. (which Darrel linked to in his answer)

    A full example from 2013 with Sinatra can be found at: http://html5hacks.com/blog/2013/04/21/push-notifications-to-the-browser-with-server-sent-events/

    There is also a 2010 HTML5 Rocks article: http://www.html5rocks.com/en/tutorials/eventsource/basics/ , but the spec is likely t have changed a bit since.

    Most current browsers support this API, with the notable exception of IE11: http://caniuse.com/#feat=eventsource

提交回复
热议问题