15

I'm trying to debug some tricky behaviour in my web application: It appears as though an XHR GET request is being sent by the client, but the server never actually receives it. Furthermore, the client seems to receive duplicate data in the unseen request as the previous XHR request it sends.

Further confounding matters, Firebug colors the second XHR request as light gray in the Net panel (the request here is third from the bottom, the second "GET test"):

enter image description here

I haven't been able to find any documentation about what this coloring means. I think if I understood this, it might help explain this unusual behaviour.

If anyone has any insight, I'd appreciate if you could let me know.

seanhussey
  • 379
  • 3
  • 10
jbeard4
  • 12,664
  • 4
  • 57
  • 67

1 Answers1

18

"Firebug color codes requests that are served from the cache in a lighter gray..."

So the reason the server doesn't see the request is that the client never actually sends it, it simply receives the response from its cache. If you're using jQuery, there is a cache property that you can use on ajax() to prevent AJAX requests from being cached. If you're not using jQuery you can append a dummy parameter to the end of the request URL that has a value of the current time in milliseconds (this is in fact what jQuery does I believe).

url + "?v=" + (new Date()).getMilliseconds()

This should ensure the URL is always unique and prevent the browser from using caching.

dbb
  • 1,100
  • 6
  • 12
  • +1 anyway there is something that I still do not understand. When you close and re-open Firefix on the same page you were previously viewing, Firefox makes all those grey requests (according to your link those are requests made to the cache and not to the server). But when you navigate the same site from one page to another Firefox does not even make those grey request. This really confuses me, if those files are always cached, why does Firefox behaves differently? See my question: http://stackoverflow.com/questions/10048740/ – Marco Demaio Apr 13 '12 at 14:11
  • Firefox implements two types of caches. An HTTP cache and a Back-Forward cache. See http://www.softwareishard.com/blog/firebug/firebug-16-tracking-also-bfcache-reads/. Only BFCache reads are currently displayed in gray. – Sebastian Zartner Jun 25 '12 at 09:26
  • Or you could indicate the expected lifetime of each entity in the cache-control HTTP header. Or put enough information in the URL to identify the entity uniquely, exploiting caching if the same thing is requested subsequently. – Szocske Jan 14 '13 at 15:15