1

I have a webpage on which AJAX is working and getting the data which is constantly modifying the page every one minute.

Now in case more than 1 tabs of the page is opened, there will be lot of calls happening and i am worried that might choke the server down.

Is there any way that we can stop the calls and javascript load in the old tabs if a new tab for the page is opened?

Thanks for the advice in advance.

Nikhil Tikoo
  • 365
  • 1
  • 9
  • 31
  • 1
    how many users do you anticipate having for this webpage? If another tab is opened, it just counts as one more concurrent user. If you are anticipating hundreds of users, then one or two more should not really be a problem for you. (This is assuming one open tab normally equals one user and their expected usage pattern). But if you really think it's necessary, http://stackoverflow.com/questions/25661543/how-to-know-if-browser-tab-is-already-open-using-javascript might help. Or this one http://stackoverflow.com/questions/23690666/check-if-my-website-is-open-in-another-tab – ADyson Feb 21 '17 at 14:17
  • @ADyson We're talking about more than 400-500 users here. – Nikhil Tikoo Feb 21 '17 at 14:23
  • Is the problem really multiple tabs being open? Isn't the problem your inability to determine a user and their session? – Waxi Feb 21 '17 at 14:25
  • 1
    @Waxi I don't know how to approach this problem. That's why asking for advice. Open to any suggestions. :) – Nikhil Tikoo Feb 21 '17 at 14:28
  • 2
    Another approach would be to only run your ajax code if the tab is active. http://stackoverflow.com/questions/1760250/how-to-tell-if-browser-tab-is-active – Waxi Feb 21 '17 at 14:32
  • Generate cookie, constantly save current timestamp. When window open, check for cookie and if the timestamp is older than X seconds, this is now the only window, otherwise abort. As long as the user doesn't open multiple browsers, this should do it. – Emil S. Jørgensen Feb 21 '17 at 14:41
  • @NikhilTikoo most users will not use multiple tabs ordinarily for one site. You can't stop them opening multiple browsers and thus having multiple sessions. But again this will be a minority. However, if it's a popular site, like social media that people might check often, then much more likely you can't stop them having it open on multiple devices simultaneously (mobile, tablet, PC, work PC left switched on at night with tabs open. etc). So if you anticipate 500 concurrent users, scale your deployment for 1000 and you'll probably be fine, whether they open multiple tabs or not. – ADyson Feb 21 '17 at 14:51
  • The [page visibility API](https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API) might be helpful. Using a [shared worker](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker) to do AJAX calls would probably be a good approach, although IE and Edge [don't currently support](http://caniuse.com/sharedworkers/embed/eras=-3,&description&links) it. – Useless Code Feb 21 '17 at 15:35

0 Answers0