質問

For example, when we have new message on http://facebook.com or http://gmail.com, site gives us signal about this, and this happened without refresh page. how it works? I Imagine this so:

some Jhon is registered user on site.

There is javascript code, which every 10 seconds sends AJAX request to messages table, for check: in table, has or not unread messages for john (architecture, how marking ready / unread messages, here not important), if Yes, site give signal to Jhon "You have several new messages".

Tell please, I am closer to the truth or not? If yes, I have also one questions please.

役に立ちましたか?

解決

In modern sites we use websockets which enable the server to push information to the browser with less overhead and no delay. That's what's used on SO.

But as some browsers still don't support them, we must sometimes fall back to a pull-loop as the one you describe.

On the server it may be handled with a queue instead of database queries at each browser request. But there are probably many different implementations on this point.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top