3

I have created application in which on each page at header loading the notifications, messages using the ajax call.

I have repeated the action with difference of half minute.

So after every half minute the new request to server has initiated.

I found that if user open the application in multiple tabs then each tab fire the request to server for the new notification/message check.

So each new tab create 1 extra requests.

How do I normalize the condition?

I mean to say---I just want to fire the single request to server for the notification/message check all-thought user open multiple tab and also update the data in each opened tab of application.

Pankaj Badukale
  • 1,991
  • 2
  • 18
  • 32

2 Answers2

2

Maybe u can check with focus blur which tab is active and only send request from the active tab and store the result in localstorage. And add a EventListener to localstorage so that u can update the other tabs.

micha
  • 1,238
  • 10
  • 7
  • Yes this will work...I have found the same type of question on stackoverflow. Actually your answer has given me idea to search. Thanks. Here http://stackoverflow.com/questions/1760250/how-to-tell-if-browser-tab-is-active – Pankaj Badukale Oct 14 '14 at 13:29
1

Maybe for each parameter you could store its value and a timestamp in a cookie and check it before your send your request. You could also use local storage to do that. http://www.html5rocks.com/en/features/storage

briice
  • 76
  • 1
  • 1
    Logically I think, this will work. but if your internet connection is slow as much that for the request and response need more than a minute in this case I don't think this will work. Or any case if your request delay same problem may come to front. – Pankaj Badukale Oct 14 '14 at 12:46
  • in that case the first to request the server can set a flag in a cookie that will stop the other tabs to do the same. They will check again a few seconds later, and again, and again, until the first tab got the answer and edited the cookie. Would that work for you? AFAIK, there's no better way than cookies to exchanges messages between tabs. – briice Oct 14 '14 at 13:01
  • yes you are right because we don't have any option for data exchange in browser locally. But I need to add constrains for request. – Pankaj Badukale Oct 14 '14 at 13:36