0

After implementing tracking code for recording the response time of API calls using XHR, it was noticed that sometimes the value is null in our reports. After a bit of investigation, it appears that sometimes happens because the response is loaded from the cache in Chromium, so therefore, the calculated response time is 0 ms.

One potential fix for is to set up the XHR to not use the browser cache, but it is not an ideal approach because that puts more load on the servers. Having null values in the reports is also an issue because it is not apparent whether or not the null value is there because the response was loaded from the cache, or due to something failing in various edge cases.

That said, is there a way using JavaScript in Chromium to detect if a response was or was not loaded from the browser cache? Also, this is a single-browser application, so worries about the solution being cross-browser.

Joshua Dannemann
  • 2,003
  • 1
  • 14
  • 34
  • 1
    How are you recording the response time? – Shelvacu Mar 28 '16 at 18:43
  • By comparing timestamps – Joshua Dannemann Mar 28 '16 at 18:44
  • Can you post the code? – Shelvacu Mar 28 '16 at 18:44
  • I could put in demo code, but it would not be that useful. Basically, before the XHR is sent we set a property startTime = (new Date()).getTime() and then we read the timestamp for the response once the callback takes place. So the # ms would be endTime - startTime. – Joshua Dannemann Mar 28 '16 at 18:48
  • Microsecond timing seems to be a good way to go about it. See: http://stackoverflow.com/questions/6233927/microsecond-timing-in-javascript However, I would still like to know if there is a way to detect if the response was loaded from the cache. – Joshua Dannemann Mar 28 '16 at 18:57

0 Answers0