How does Stack Overflow notify of server-side events without a page reload? I see no request in Firebug

前端 未结 2 1974
别那么骄傲
别那么骄傲 2020-12-25 14:21

How does Stack Overflow show the answer added/edited message without a page reload?

\"enter

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-25 15:08

    It appears to be using HTML 5 Web Sockets. They basically keep an open connection between the server and the client and, among many other things, allow the client to define event handlers to treat new data when received from the server.

    Here you'll find some basic examples and concepts about WebSockets: Introducing WebSockets: Bringing sockets to the web.

    The WebSocket specification defines an API establishing "socket" connections between a web browser and a server. In plain words: There is an persistent connection between the client and the server and both parties can start sending data at any time.

    There is also a live demo with server & client source code available.

    You might also find the following question useful: How do real time updates work?

提交回复
热议问题