What to do with chrome sending extra requests?

2019-01-03 06:19发布

Google chrome sends multiple requests to fetch a page, and that's -apparently- not a bug, but a feature. And we as developers just have to deal with it.

As far as I could dig out in five minutes, chrome does that just to make the surfing faster, so if one connection gets lost, the second will take over.

I guess if the website is well developed, then it's functionality won't break by this, because multiple requests are just not new.

But I'm just not sure if I have accounted for all the situations this feature can produce.

Would there be any special situations? Any best practices to deal with them?

Update 1: Now I see why my bank's page throws an error when I open the page with chrome! It says: "Only one window of the browser should be open." That's their solution to security threats?!!

12条回答
贪生不怕死
2楼-- · 2019-01-03 06:46

In my case, it was Chrome (v65) making a second GET /favicon.ico, even though the response was text/plain thus clearly no <link in there referring the icon. It stopped doing that after I replied with a 404.

Firefox (v59) was sending 2 requests for favicon; again it stopped doing this after the 404.

查看更多
▲ chillily
3楼-- · 2019-01-03 06:50

It also can be caused by link tags with empty href attributes, at least in Chromium (v41). For example, each of the following line will generate an additional query on the page :

<link rel="shortcut icon" href="" />
<link rel="icon" type="image/x-icon" href="" />
<link rel="icon" type="image/png" href="" />

It seams that looking for empty attributes in the page is a good starting point, either href or src.

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-03 06:50

I have just implemented a single-use Guid token (asp.net/TSQL) which is generated when the first form in a series of two (+confirmation page) is generated. The Token is recorded as "pending" in the DB when it is generated. The Guid token accompanies posts as a hidden field, and is finally marked as closed when the user operation is completed (payment). This mechanism does work, and prevents any of the forms being resubmitted after the payment is made. However, I see 2 or 3 (!?) additional tokens generated by additional requests quickly one after the other. The first request is what ends up in front of the user (localhost - so ie., me), where the generated content ends up for the other two requests I have no idea. I wondered initially why Page_Load handlers were firing mutliple times for one page impression, so I tried a flag in Http.Context.Current - but found to my dismay, that the subsequent requests come in on the same URL but with no post data, and empty Http.Context.Current arrays - ie., completely (for practical purposes) seperate http requests. How to handle this? Some sort of token and logic to refuse subsequent page body content requests while the first is still processing? I guess this could take place as a global context?

查看更多
We Are One
5楼-- · 2019-01-03 06:52

I just want to update on this one. I've encountered the same problem but on css style.

I've looked at all my src, href, script tag and none of them had an empty string. The offending entry was this:

<div class="Picture" style="background-image: url('');">&nbsp;</div>

Make sure you also check your styles for empty url string

查看更多
迷人小祖宗
6楼-- · 2019-01-03 06:54

I saw the subjected behavior while writing my server application and found that earlier answers are probably not true.

Chrome distributes a single request into multiple http ones to fetch resources in parallel. In this case, it is an image which it fetches as a separate http get.

I have attached screen shot of packet capture through wireshark.

It is for a simple get request to port 8080 for which my server returns a hello message.

Chrome sends the second get request for obtaining favorite icon which you see on top of every tab opened. It is NOT a second get to cater time out or any such thing.

It should be considered another element that differs across browsers.

Here is a reference question that i found latter

Chrome sends two requests SO

chrome requests favorite icon

Chrome issue on google code

查看更多
淡お忘
7楼-- · 2019-01-03 06:56

I was having this problem, but none of the solutions here were the issue. For me, it was caused by the APNG extension in Chrome (support for animated PNGs). Once I disabled that extension, I no longer saw double requests for images in the browser. I should note that regardless of whether the page was outputting a PNG image, disabling this extension fixed the issue (i.e., APNG seems to cause the issue for images regardless of image type, they don't have to be PNG).

I had many other extensions as well (such as "Web Developer" which many have suggested is the issue), and those were not the problem. Disabling them did not fix the issue. I'm also running in Developer Mode and that didn't make a difference for me at all.

查看更多
登录 后发表回答