52

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

Kevin Le - Khnle
  • 10,579
  • 11
  • 54
  • 80
Cg Alive
  • 639
  • 1
  • 6
  • 11
  • 2
    do you have a link to anywhere this is officially documented? – fearofawhackplanet Dec 16 '10 at 12:22
  • I got this from a question in stackoverflow: "Chrome is trying some aggressive tactics in its developer builds (I think that is cool). What they're doing is speculatively opening sockets to servers, and also opening a second socket if their first attempt doesn't get a response quickly enough. It's pretty easy to see how a bug in this stuff, or even just the expected behavior, could trigger abuse filters. But, as I said, I think it is worth doing. All these web startups will make more money if the Web is faster." – Cg Alive Dec 16 '10 at 12:30
  • 1
    A Chromium issue touches on this http://code.google.com/p/chromium/issues/detail?id=39402#c11 – jrummell Nov 09 '11 at 21:09
  • I am getting multiple requests for same url, when fetching some PDFs. The number of requests depend on the file, so may be something in the file. For new files (not requested before) server returns http-code 200, then 304 for all subsequent. (200 is “ok, here is the doc”, 304 is “the page in your cache is still valid”), Therefore chrome received the first, put it in the cache, and then requested the others, using the cache-tag from the first. ( I did not see this with firefox). – ctrl-alt-delor Jan 07 '16 at 22:04
  • 1
    This is not a Chrome feature today as far as I know. This usually happens due to a particular reason. In this post you'll find many of those possible reasons: https://stackoverflow.com/questions/2009092/page-loads-twice-in-google-chrome/66266716#66266716 – Andrew F. Apr 09 '21 at 14:05

14 Answers14

18

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

chrome requests favorite icon

Chrome issue on google code

fkl
  • 5,412
  • 4
  • 28
  • 68
18

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

Peter
  • 965
  • 7
  • 13
  • I'm using the same version, but I see the behavior. Try calling a script that increments a number in a file. – Cg Alive Dec 16 '10 at 13:40
  • I've not managed to reproduce it, I wrote a quick script which appends to a file and I only get one line in the file per click. I'm using the Linux build so maybe it's not enabled there yet – Peter Dec 16 '10 at 14:05
  • Not changing application state from a GET is not always achievable. What if the user has selected "Log me on automatically" so we analyse the cookie, determine that they can be logged on automatically and then update the time of the "last logged in" attribute in the User object. That is an application state change. – Volksman Feb 15 '17 at 19:20
8

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.

Jérôme
  • 175
  • 1
  • 10
4

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.

RomanK
  • 41
  • 3
4

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....

user3524983
  • 419
  • 4
  • 7
3

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?

badcop666
  • 121
  • 2
  • 9
2

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.

lcfd
  • 1,326
  • 10
  • 12
2

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

MDuh
  • 415
  • 1
  • 7
  • 19
2

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.

Optimus
  • 1,703
  • 4
  • 22
  • 41
1

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.

Travitron
  • 593
  • 6
  • 11
0

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.

Community
  • 1
  • 1
jfunez
  • 397
  • 6
  • 23
0

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.

Carnaru Valentin
  • 1,690
  • 17
  • 27
0

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.

Rustam A.
  • 809
  • 8
  • 15
0

It could be situation when Chrome send in start the request with method OPTIONS and only the second is real request with method GET. Usually in code we deal only with GET (or POST/PUT/DELETE..) but not with OPTIONS. Check if the first request has method OPTIONS.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 07 '23 at 02:56