May 022006
 

For the initial release of Naymz, Michele Lopatin and I have been tracking down a bug that was causing the browser to fetch the same URL twice. In order to track this down I had to systematically comment out lines of HTML in the page until it stopped and then uncomment lines until it came back to figure out exact what was requesting the page the second time. This was a huge issue because it essentially doubled the load on the server and the bandwidth usage.

As it turns out in FireFox (and possibly IE, but I’m not sure as I run Linux completely now), empty image src attributes cause the browser to request the same URL of the current page the browser is pointing to. This is really DUMB on the FireFox developers (or the W3C if it is in the specification) part since this should just error out:

<img src=””/>

Instead they decided to try requesting the URL of the current page again in hopes that it would magically return an image, which of course it is never really gonna do because the current URL is what your are rendering. Lame. At least we figured it out before launching and getting pounded with double requests.

  54 Responses to “Is your browser requesting a page twice?”

  1. I haven’t noticed that, but looking over my blog stats I was seeing some bizarre prefetch behavior (two pages being requested by a browser in a very short time span). This article sorted it out for me: http://www.petefreitag.com/item/312.cfm.

    Actually, doing a bit of research reveals that what IE and Moz are doing is according to the spec. The src attribute of an image is a URI, and according to the definition of a URI:

    4.2. Same-document References

    A URI reference that does not contain a URI is a reference to the
    current document. In other words, an empty URI reference within a
    document is interpreted as a reference to the start of that document,
    and a reference containing only a fragment identifier is a reference
    to the identified fragment of that document.

    I will admit that this is rather counter intuitive for an img src.

  2. This seems like a cheap way to allow links to link to the current page, which really is the same as a refresh, but besides that behavior I can’t think of any other URIs that need to be the current page. This just seems dangerous to me. They should have made this point to some universally non-existent URI such as page:null or something.

    Then again we all know how I feel about the current web! Haha

  3. Why in the world do you have img src tags that reference nothing to begin with? I think the spec is lame too, but couldn’t the author of that spec say the same about your page with lame empty tags!?

    Sorry.. had to ask..

  4. Well, mister smarty pants! Being a nihilist I like empty images. In fact, images that have colors, dimensions, shapes, yeah they really piss me off! The beauty of nothing is absolute.

    Ooooooorrrrrr…. You might have a variable that ends up being empty for some reason and didn’t do a null check on the page. Not a good case, because it’s essentially a bug, but if the spec just said to ignore these img tags it wouldn’t bite you quite so hard.

    example:

    <img src=”${foo.bar}”/>

  5. Wow! Great example. I never really understood what means. A check for null. Genius! I wanted to understand more about this “null” you speak of and found:
    http://en.wikipedia.org/wiki/Null_%28computer%29

    Being enslaved by the German community, I can respect your nilhilist stance.

  6. Why in the world do you have img src tags that reference nothing to begin with

  7. See my comment above. If you have a variable that is null in your JSP, ASP, PHP, whatever, you might end up with an image with an empty source attribute. Now don’t get me wrong, this doesn’t mean that it isn’t a bug, but that bug could eat up some serious band-width on the server since each request is done at least twice if not more.

  8. This doesn’t seem to happen in IE.

    I ran into it when I didn’t specify an SRC because I am waiting for a Graphic Designer to furnish images for my project.

    Instead, I specified alt text, incorrectly assuming that being a “good w3 developer” by specifying the ALT text would prevent my browser from executing a GET for my page again.

    Of course, I wasn’t conscisouly thinking that specifying ALT would prevent this , because it’s completely ridiculous that it does this in the first place!

  9. So does the ALT tag prevent it from requesting the current URL again or is it just IE not following the crazy W3C specification (which is normal so I won’t be astonished if that’s the case)?

  10. IE, amazingly, does something worse: it requests the directory the current page belongs to. I understand the underlying logic. If the page /x/y.html has the tag , the browser requests /x/a — so degenerately should cause a request to /x/

    Madness.

  11. Hi All,

    I dont think this is happening because of img tags with src=””. I had the same problem with IE and i am not using img tags anywhere in my page. It is working well in Firefox and Netscape. Is there any other reasons?

  12. This is definitely a by-product of img src=”” tags in the page, but I would imagine that IE does this for a bunch of other things as well. I would start by commenting out the entire JSP/ASP/RHTML/PHP (or whatever you are using) file and then slowly uncommenting each piece until you figure out which line of code is causing the double request. Then purge it with the force of a thousand lions, or something like that.

  13. Hi All,

    I found the root cause of this issue. This is happening becuase of “input type=’image'” tags. Two my ASP pages are using these tags to submit the page with the help a javascript function on onclick event. Now i changed these tags to “img”, the issue got resolved.

    Thanks,
    Madhu.

  14. I found that this also occurs (in Firefox1.5, Opera8.0, not IE7.0) when there is a blank url reference in the page’s in-line css.
    (But not if the css file is linked.)

    Firebug for Firefox helps alot!

  15. above chopped my code; this

    style='background:#fff url();'

  16. Hi,

    You really saved my beeswax with posting this comment, i uncommented a line in my PHP menu object which disabled any images being placed before them, so empty tags which also kept creating a dublicate request which was starting to mess the rest of the site up, but god thanking for find this comment i’ve saved hours of debugging my PHP to see if it was creating a problem.

    Cheers again. :)

  17. Thanks for pointing this out! I was using the onerror attribute of the img tag to try to initiate some javascript that would replace broken images with a placeholder image, but the double-requests were making a mess out of my cookies… I had a feeling the empty tags might by the reason, so I googled < empty src tag on img > and found your site. Thanks for the confirmation!

  18. No Wonder. I had this problem about 1-2 years ago. One of our PHP pages creates user account, and if the new account coincides with an existing account, an error message is displayed, indicating the account exist. With firefox, each time a totally new account is created, it mentions that the account exist. It seems there’s a double page request there. What happens is that the new account is created, but the successful message is not shown, indicating the output was not sent to the browser internally. Then the second request is made and the error message is shown, this time to the browser. This is not a page refresh at all, but only the second request is being displayed to the browser. We spent loads of time going through every line of PHP code, but could never find the bug. In case of a GET or POST page, firefox will do it twice, and could really ruin dynamic scripts, if certain checks are not in place!

  19. I found that the double request is done whenever the response contains the tag in the body…
    I narrowed it down to just creating an a.html file in my http server dir, and requesting that file

    test 1:
    contents: hello
    results: one request processed

    test 2:
    contents: hello
    results: two requests processed

    test 3:
    contents: hello
    results: two requests processed

    so it appears that ff checks for

  20. need to view source to see the html around hello sorry

    ust don’t put

  21. Ok, finalized the issue here.
    Returning any mark up language tags that require a src URL as a parameter but none is specified….

    so,

    will make firefox re-request the original URL

  22. This issue had me stumped for a long time because a site I was developing had no images, external stylesheets or javascript sources whatsoever, yet still two requests were being made to the server for every single page!

    Worse still, the response from the second of those requests instantly overwrote the response from the first yet left only one entry in the browser’s history object – this made debugging pretty tricky.

    Anyway, after much furrowing of brow and tea-drinking the root cause of this problem seems to have boiled down to an extra “;” (semi-colon) in the meta “Content-Type” tag. I had …

    meta http-equiv=”Content-Type” content=”text/html; charset=utf-8;”

    instead of …

    meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″

    (removed the semi-colon from the charset).

    It was an oversight on my part, but it’s strange that Firefox decides to behave in this manner (IE seemingly doesn’t mind the extra semi-colon).

  23. It’s crazy but after removing an image with null src attribute resolved the issue. crazy from the FF side

  24. Same issue, but different.

    First of all, thanks for all the above, it helped me to figure out a solution to my version of the problem.

    My problem:
    – FireFox loaded a certain page twice, no clue why.
    – NO src=”” attribute in any of my img tags
    – The charset=utf-8 did not have the semi-colon in the end but this lead me to the answer

    After locating the problem by commenting out line by line I found that the charset meta was causing the problem. At some point I changed the utf-8 to iso-8859-1 and the page loaded only once! Switching it back to utf-8 introduced the problem again.

    It seems that my source php files should have had the same encoding as the charset you give the output xhtml. Changing the php-file encoding into utf-8 solved the problem.

    I found the answer on the following site (Section 1.5):
    http://www.imarc.net/communique/view/310/9_expert_css_ideas_you_should_think_twice_about_before_using

    Enjoy (en)coding!

  25. I had this issue only in Firefox 2.0.0.13. Safari 3.1 and Opera 8.54 did not exhibit this behavior. Several of my POST requests were processed twice resulting in 2 (and later 3 for some reason) comment entries etc for each submission. Found this via google and then located an empty src in one of my templates. Removed and all in now fine. Thanks!

  26. The example that made me search for this answer is this:

    function setMyImage(){
    document.getElementById(‘myImage’).src=myImageURL;
    }

    setMyImage() is called at some point to fill in the image URL, which is after the browser has requested the page a second time. The image displays correctly so you will only know that it was requested twice by checking the logs.

    Thanx for this topic.

    cl

  27. When first running into this whole thing this morning, I couldn’t even possible imagine that it is caused by Firefox?! I took scripts apart, I got all my http traffic logged, I had my server write debug files, … Until I tried to run my application in IE and Opera. They both made only one request. Firefox strangely made two.
    After finally googling this little big problem, I came across the img src=”” issue, but like many others, I did not have empty img-tags. So I found out about the Content-charset thing. Oh wait! Does my content even have a single little tiny itty meta-tag? Nope. Not even the charset one.

    Thanks a lot, especially @Finn (comment above).. Everything works alright now.

    Paul

  28. Found one more cause for this behavior: mismatch of charset in header and meta:

    HTTP/1.x 200 OK
    Content-Type: text/html

  29. (meta example in previous post was trimmed)

    HTTP/1.x 200 OK
    Content-Type: text/html

    <meta http-equiv=”Content-Type” content=”text/html; charset=windows-1251″>

  30. I am soooo grateful I found this thread… thought I was losing my mind. My solution ws the same as Finn: “I changed the utf-8 to iso-8859-1 and the page loaded only once! Switching it back to utf-8 introduced the problem again.” I would never in a million years have thought to make such a change and the problem was really hanging me up bad. Thank you so much!

  31. Thank you for posting this thread.

    I’ve had a similar behaviour with a simple hit counter caused by an img src tag set to a non-existant file.

    In this case Firefox (v.3.0.3) loads the page twice and Safari (version 3.1.2) does it three times.

  32. […] Una discussione sull’argomento si può trovare su Invert Your Mind. […]

  33. Thanks for posting this. Saved me losing all my hair.
    For me it turned out to be some nifty java script I had inherited pre-processing pages (and img tags).

    Thanks again.

  34. Just ran into this problem in FF 3.

    To avoid this problem how can you, on the server, recognize whether or not a given request is coming from an empty img src=””? MSIE seems to set the HTTP_ACCEPT header to */* on reload and doesn’t distringuish between img and page requests.

  35. Same deal in a page where the src is set by js in response to the user making a choice in a drop-down. So the solution was

    instead of

  36. Try again.

    So the solution was

    <img>

    instead of

    <img src=”>

  37. Here is another example:

    <link rel=”stylesheet” type=”text/css” href=”/stylesheets/.css” />

    In this case, if styleSheetName is an empty string, the page will also be requested twice.

  38. This happens also with null objects / flash applets too. Make sure all your src’s aren’t null.

    Was driving me nuts until i found this little bugger….
    <embed src=””

  39. In my case it was the combination of

    Firefox 3 and

    that caused the requests to be executed twice.

    After changing the charset from iso-8859-15 to iso-8859-1 my application worked fine.

  40. Hey. In my case firebug caused the second request.

  41. Thanks for these hints!

    I had neither missing or wrong charset meta definition nor the wrong charset for my content, but the problem was related to international characters (german umlauts in my case).

    *After disabling the Firefox charset encoding auto detection the problem disappeared.*

    Don’t know though why FF should even try to autodetect if there’s a charset meta header available…

  42. Thanks for these hints!

    I had neither missing or wrong charset meta definition nor the wrong charset for my content, but the problem was reoated to international characters (german umlauts in my case).

    *After disabling the Firefox charset encoding auto detection the problem disappeared.*

    Don’t know though why FF should even try to autodetect if there’s a charset meta header available…;

  43. […] altro articolo presenta come altra possibile causa delle doppie richieste la presenza di tag img con […]

  44. Thanks for all the input on here. That lead me to the solution in my case.

    Firefox (4 & 5) requested the page twice when the site had meta tags (description, abstract, keywords) with utf-8 contents even if the charset was set to utf-8. The solution was to place the http-equiv meta tag (that sets the charset) BEFORE the other meta tags containing utf-8.

  45. @Finn: Thanks a lot. It solved the issue.

  46. […] hours, I started typing random words into Google hoping to find the answer. I quickly stumbled upon this. My thanks go out to Mr Brian Pontarelli, as he has spent many more hours than I tracking down the […]

  47. One more suggestion

    Put

    direct after like below

    • put

      <meta http-equiv=content-type content=text/html charset=utf8 />

      direct after “<head>” like below

      <head>
      <meta http-equiv=content-type content=text/html charset=utf8 />

  48. Thanks it saved me lot

    my jsp page contains caused the problem

    i changed it to
    now page is loading once.
    thanks guys

  49. After three days of bashing my head against a brick wall trying to fix a bug where I was receiving multiple password reset emails, this 12-year-old blog post and thread helped me solve the issue in an hour.

  50. Thanks for all the hints!
    Unfortunately it didn’t solve my problem. I have a real simple page with a small stylesheet. It loads twice in FF and works fine Chrome in Edge. When I remove the stylesheet or comment out all of the lines in the stylesheet file it works fine in FF. It seems to first load w/o the stylesheet and then again with the style.

    Why can this be?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.