Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

enter image description here

Yes, I know it will happen with Ajax. So I opened Firebug in a browser to check it, to see whether any requests are coming in a particular interval of time. But I don't see any request coming in Firebug.

Can we perform a request without it showing in Firebug? Are there any other ideas behind this or is my concept totally wrong?

like image 566
Justin John Avatar asked Sep 14 '12 13:09

Justin John


2 Answers

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?

like image 83
Xavi López Avatar answered Oct 19 '22 20:10

Xavi López


To add to Xavi's answer, if you want to get started with web sockets without having to understand all the internals, you might try out Pusher, a library for multiple platforms (including PHP) that makes push notifications on the web very straightforward.

I do not work for Pusher; it's just a product I've found very useful in the past. I've always used the free version for small personal projects, though I would probably pay if I ever used it on a larger application.

like image 3
Dan Tao Avatar answered Oct 19 '22 21:10

Dan Tao