How would it be best to automatically update the content on the page (without reloading)? The task is to update not several blocks. Replacing the entire html is not suitable, takes a lot of resources. For each block, making your own request is also not an option, since there are more than 5 blocks, there will be a load. And what if several tabs of the page are opened - the requests will come from several tabs at once ...

How to do it right and with minimal resource consumption.

  • For some reason no one suggested using WebSocket =) which is strange =) - Vladimir Klykov

2 answers 2

  1. 5 rekvestov - not very scary.
  2. You can make a separate script to check for updates, and only then, if necessary, load them
  3. You can check if the tab is active. But, here you have to look at the task. Not everywhere is acceptable
  4. Replace the "all html" is also not necessary. With the same success, you could just update the tab. You need to work with concrete blocks.

    On the server side, make an array with the contents for each block, and encode it in json. Then this json is returned to you in the document from where you are making the ajax request. Then you can already stuff everything in separate blocks on the page.

    • Can there be any practical examples of such an implementation? - iKey
    • Paste your code, I will outline how to remake it. - boneskhv