How do websites instantly update their content using AJAX?

Today, when I used Google+ in two separate browsers, I sent something with one browser. The message appeared almost instantly in the second browser (maybe 0.5 seconds delay). How does Google achieve this? Do they constantly send AJax requests to check for new messages? Wouldn't that hurt the server?

+1
source share
4 answers

You can use various methods for this:

  • Websockets
  • AJAX Long Term Survey
  • page timers
  • floating frames

Each has its own reservations and opportunities.

If you are interested in real-time application capabilities, you can take a look at socket.io , which is a great abstraction library for all of these technologies, so it will use the one that is best supported in your browser.

+2
source

I canโ€™t say how Google is for sure, but they would have to use some kind of push technology. HTML5 WebSockets is something that can be done in new browsers. In older browsers that do not support web ports, the client usually checks the server periodically. See socket.io for a neat cross-browser implementation of WebSockets with backups of other methods if the browser does not support it, here .

0
source

I guess one of the methods that they can use is to send an AJAX request immediately and then block it on the server side until a timeout or content is sent.

0
source

For many years, Google has used Comet or Reverse Ajax: http://en.wikipedia.org/wiki/Comet_(programming ))

However, I believe that they are using HTML5 WebSocket now that the API is ready: http://en.wikipedia.org/wiki/WebSocket/

http://dev.w3.org/html5/websockets/

0
source

Source: https://habr.com/ru/post/1412766/


All Articles