How to normalize ajax call for multiple tabs?

I have created an application where on every page in the header, notifications, messages are loaded using an ajax call.

I repeated the action half a minute apart.

So, every half a minute, a new request to the server starts.

I found that if the user opens the app in multiple tabs, each tab triggers a request to the server to check for a new notification / message.

So, each new tab creates 1 additional request.

How do I normalize the condition?

What I mean is --- I just want to run a single request to the server to check notifications / messages so that the entire thinking user has multiple tabs open and also refreshes the data on every open application tab.

+3


source to share


2 answers


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



+2


source


Perhaps for each parameter, you can store its value and timestamp in a cookie and check it before submitting your request. You can also use local storage. http://www.html5rocks.com/en/features/storage



+1


source







All Articles