Does multiple tabs of same site send multiple ajax calls?

余生长醉 提交于 2020-01-07 05:32:25

问题


Let imagine we have site what every second check is there any new messages:

$(function(){
    setInterval(function(){
        $.ajax({
            url: 'message_check.php',
            success: function(data){
               if(data)$('#someDiv').html('NEW MESSAGE!');              
            }
         });
    },1000);
});

Now someone opened 3 tabs with different pages of my site.

How many call I'll get every second, three or one?

  • if one then how tabs sinc?

  • if three then we lost very very much performance, right?

Noticed what Firebug show same console for different pages of same site. It means what FireFox in my case (and I hope other browser too) understand what it same site and can avoid multiple calls.

I think about saving result into cookie and make call only if it's not "fresh", but don't want to reinvent the wheel.


回答1:


I think its depends on the browser you use. Some browsers use only 2 concurrect connections to the server, hence you will get up to 2 concurrent hits from your multi-tab browser client. So if you javascript generates multiple requests, they will be quied & managed by the browser.



来源:https://stackoverflow.com/questions/15765579/does-multiple-tabs-of-same-site-send-multiple-ajax-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!