开发者

What to do with chrome sending extra requests?

开发者 https://www.devze.com 2023-01-30 17:22 出处:网络
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.

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?!!


Your best bet is to follow standard web development best practises: don't change application state as a result of a GET call.

If you're worried I recommend updating your data layer unit tests for GET calls to be duplicated & ensure they return the same data.

(I'm not seeing this behaviour with Chrome 8.0.552.224, by the way, is very new?)


I saw the subjected behavior while writing a 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 the 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. However, doing things in multiple http requests in parallel is kind of a standard thing in browsers as of 2018.

Here is a reference question that i found latter

Chrome sends two requests SO

What to do with chrome sending extra requests?

Chrome issue on google code


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.


This behavior can be caused by SRC='' or SRC='#' in IMG or (as in my case) IFRAME tag. Replacing '#' with 'about:blank" has fixed the problem.

Here http://forums.mozillazine.org/viewtopic.php?f=7&t=1816755 they say that SCRIPT tags can be the issue as well.


My observation of this characteristic (bug/feature/whatever) occurs when I am typing in a URL and the Autocomplete lands on a match while still typing in the URL. Chrome takes that match and fetches the page, I assume for the caching benefits that would occur when loading the page yourself....


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?


This only happens when I enable "webug" extension (which is a FirePHP replacement for chrome). If I disable the extension, server only gets one request.


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


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.


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.


I'm having the same bug. And like the previous answer this issue is because I've installed the Validator chrome extension Once disable the extension, works normally.


In my case I have enpoint (json) data to a different server and browser make first an empty request(Request Method:OPTIONS) to check if a endpoint accept requests from my server, Same-origin policy. Also goot to know is a Angular 1 App. In conclusion I make requests from localhost to a online fake json data.


I had empty tcp packet sent by Chrome to my simple server before normal html GET query and /favicon after. Favicon wasn`t a problem but empty tcp was, since my server was waiting either for data or for connection to be finished. It had no data and wouldn't release connection for 2 minutes. So thread was hanging for 2 minutes.

Jrummell's Link in a comment to original post helped me. It says empty tcp packets could be caused by "Predict network actions to improve page load performance" setting. I tried turning off prediction settings one by one and it worked. In chrome version 73.0.3683.86 (Official Build) (64-bit) this behavior was caused by chrome setting "Use a prediction service to load pages more quickly" turned on.

So in chrome~73 you can try going to setting -> advanced -> privacy and security -> Use a prediction service to load pages more quickly and turn it OFF.

0

精彩评论

暂无评论...
验证码 换一张
取 消