8

I've created a simple Node.js app which logs to console the current request.url for every incoming HTTP request. When I refresh the page in Chrome on Mac OS X ML, I receive two requests for the same page. Why?

In comparison, when I use curl and request the same page, I receive only one request. Same one request if I refresh the page in Safari.

Why would Chrome send two requests for the same page?

Edit: I've looked into the request.headers and found one difference: the accept header.

Here is the header for the first request. Notice, it accepts a list of specific mimes.

{ host: 'www.pulsr.local:1337',
  connection: 'keep-alive',
  'cache-control': 'max-age=0',
  accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17',
  'accept-encoding': 'gzip,deflate,sdch',
  'accept-language': 'en-US,en;q=0.8',
  'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
  cookie: 'PULSRSESSID=BBtDAWMVgbQZ8lXA6wv4Wg/vwwI=; PULSRSESSID=dsGxP494UxJueit2/u79AFiM5fw=' }

Here is the second request. This time it accepts everything.

{ host: 'www.pulsr.local:1337',
  connection: 'keep-alive',
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17',
  accept: '*/*',
  'accept-encoding': 'gzip,deflate,sdch',
  'accept-language': 'en-US,en;q=0.8',
  'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
  cookie: 'PULSRSESSID=VGWRSG9zIokHjA2vLa1b+/fUqu8=; PULSRSESSID=dsGxP494UxJueit2/u79AFiM5fw=' }

Edit 2: I've checked and see that both requests are GET requests.

esengineer
  • 9,514
  • 7
  • 45
  • 69

4 Answers4

5

I think it's to do with this bug in Chrome where it's sending a request for the favicon on every request. Firefox and other browsers do this on their first request but cache it.

Jamie
  • 674
  • 1
  • 10
  • 30
  • Good guess, but I've checked that on the very first request it sends 3 requests (2 that I've mentioned + 1 for favicon). After that there are only 2 requests for each page. – esengineer Feb 07 '13 at 14:23
  • Eventually, I'm inclined to believe that this bug is the cause. – esengineer Mar 05 '13 at 12:20
3

As found in another answer, it can be caused by empty src attributes on images or iframes. I had the same problem : 4 requests on the exact same page — not on the favicon — from Chromium, when doing only 1 page refresh. In my case, I found out it was due to empty href attributes on link tags :

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

So 1 request for my page reload, and 1 request for each of the 3 above links.

Community
  • 1
  • 1
Jérôme
  • 175
  • 1
  • 10
0

be aware of firebug light extension on chrome .. that was my problem

lhenry2k
  • 99
  • 1
  • 5
0

In my case an iframe with src="#" caused page to open twice

<iframe src="#" class="iframe lazyload" id="youtube-player-iframe" allow="autoplay"></iframe>
Dzmitry Dranitski
  • 165
  • 1
  • 4
  • 13