I have a mock project where I am testing Etag
and If-None-Match
behavior on different browsers. A Get
request is sent on page load and I will always respond with 200
and assign a new Etag
value.
window.addEventListener('load', () => getEtag(false));
function getEtag() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log("Success");
}
};
xhr.onerror = function () {
console.log("Failure");
};
xhr.open("Get", "http://localhost:8080/etag", true);
xhr.send();
}
Java server side:
@GetMapping("/etag")
public String getEtag(HttpServletRequest request, HttpServletResponse response) {
response.setHeader("ETag", UUID.randomUUID());
return "";
}
I understand that this not the intended use for Etags
but bear with me. On Chrome and Firefox this works as expected. On every page load the request includes the If-None-Match
header. However on Safari the header is included only in every other request. I know there are several questions pertaining to Etags
and If-None-Match
and Safari but they are all about its complete absence. In my case the first request does not contain the If-None-Match
(as expected), the second request will but then the third request will not. It then oscillates between sending the header and not. I modified my code to return 304
if the If-None-Match
header was present which prompted Safari to send the header with every request but it would not update the Etag
value with the new one assigned. I understand that that is expected behavior, but is there a way to make Safari behave like chrome and Firefox when I return 200 and a new Etag
?