0

Morning folks,

I'm hoping someone can help me understand how to deal with 304 responses.

I have a web page that generates it's content dynamically by getting data from a REST Service using a XMLHttpRequest object, then updates the contents of the webpage.

Currently if the data is requested again within it's max-age, the REST Service returns the cached data and a Status Code of 200, but it going to change to returning no data and a 304 Status Code. I did a few quick tests of my own and as there is no data returned I have no data to display. So I'm kinda stuck on how this how process works.

I've seen lots of questions and answers explaining why and when 304 should be used, but can't find how to handle the 304 in the client code.

Hope someone can help.

sbarnby71
  • 584
  • 4
  • 7
  • 21
  • Try adding some random number at the end of url you calling (example: http://sample.com/myurl.php?randomnumber ... That should help you. – salih0vicX Sep 06 '16 at 07:35
  • 1
    Did you actually do tests *with* `XMLHttpRequest`? Because [according to this answer](http://stackoverflow.com/a/16817752), XMLHttpRequest should basically turn 304 responses into 200 responses (by changing the status code and giving back the cached response). This is also the behavior I get when testing myself. – Frxstrem Sep 06 '16 at 07:37
  • Frxstrem Yes I did run test using a XMLHttpRequest object and I get a 304 Status Code and .ResponseText is blank. – sbarnby71 Sep 06 '16 at 08:02
  • salih0vicX I've tried this with adding a random number at the end of the url, but that would make the request unique and therefore not be cached anyway. – sbarnby71 Sep 06 '16 at 08:11

1 Answers1

0

Well the solution was very simple, I had the "Always Refresh From Server" setting on whilst testing this in IE.

sbarnby71
  • 584
  • 4
  • 7
  • 21