How does incoming mail notification on Gmail works?

前端 未结 4 596
无人共我
无人共我 2021-01-04 05:50

I\'m wondering how it\'s implemented in Gmail, that every time you receive e-mail, the list of mails is automatically refreshed. It looks like the server is sending some kin

相关标签:
4条回答
  • 2021-01-04 06:10

    gmail is, in fact, polling the server for updates. Not as often as every two seconds, though. That would be madness. A bit of testing with Tamper Data makes it look like maybe every 20 seconds, though there seem to be multiple events going through that confuse it a bit.

    Regarding your edit, I imagine they might have a last-activity timestamp on the account tracking in their database, with the client polling query retrieving that via Ajax and comparing with its last sync to determine whether it needs to do a full update.

    0 讨论(0)
  • 2021-01-04 06:10

    You have right with simple answer. Google Mail checking new messages on server via AJAX.

    0 讨论(0)
  • 2021-01-04 06:25

    It must be some kind of ajax listener that get informations every X seconds.

    I already set something like that for one of my projects. What I was doing is calling a function that was returning true or false. True if the page needed to be refreshed, false otherwise. Then if you have an update, you do another call to get the actual update. This way you don't have to refresh everything every time... but it's still intense on the server if you have a lot of users.

    In other words and like chaos said, it's polling the server.

    0 讨论(0)
  • 2021-01-04 06:36

    Dont know exactly which technoloy Gmail uses, but the concept is to open a channel - using reverse AJAX, comet or sprocket based techniques.

    Think of it as the client requesting the server for data, but the server does not return for one minute unless it has new mail. Using this technique, the client can almost show the results in a real time manner and it does not have to poll every 2 secs. Makes sense?

    0 讨论(0)
提交回复
热议问题