esengineer
esengineer

Reputation: 9938

Why does a browser send two requests for the same page when it's refreshed?

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.

Upvotes: 8

Views: 8421

Answers (4)

Dzmitry Dranitski
Dzmitry Dranitski

Reputation: 679

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

<iframe src="#" class="iframe lazyload" id="youtube-player-iframe" allow="autoplay"></iframe>

Upvotes: 0

lhenry2k
lhenry2k

Reputation: 109

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

Upvotes: 0

Jamie
Jamie

Reputation: 724

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.

Upvotes: 5

J&#233;r&#244;me
J&#233;r&#244;me

Reputation: 175

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.

Upvotes: 3

Related Questions