Here is a sample code. In sequence, create four xmlhttprequests () s at the same URL. In this case, I expect four requests to go by wire with four different answers, since in this case the URL returns a new UUID for each call. In Chrome 18, Firefox, and Safari, this happens.
However, in Chrome 19, only one request is sent to the wire, but the browser acts as if all four requests are returned with the same value. That is, the callback is performed four times, but with the same response text each time. Developer tools and Wireshark confirm that only one request was actually executed.
I thought that this could be due to browser caching behavior, but playing with the client side (pragma: no-cache) and on the server side (Cache-Control: no-cache) did not help. Adding a dummy request parameter, which is different for each request, forces it to make all four actual requests, but I'm still wondering what has changed and what other way it can be handled (except for URL parameters). I also suspect that I am doing something strange or wrong, since I cannot find other people talking about it.
<!doctype HTML>
<script>
function doOne(i) {
var xh = new XMLHttpRequest();
xh.open("GET", "/uuid", true);
xh.setRequestHeader("pragma", "no-cache");
xh.onreadystatechange = function() {
if (xh.readyState == 4) {
var p = document.createElement('p');
p.innerHTML = xh.responseText;
document.body.appendChild(p);
}
}
xh.send(null);
}
window.onload = function() {
for (var i = 0; i < 4; i++) {
doOne(i);
}
}
</script>
For reference, here is what I use for the server example for this test case (web.py):
import uuid
import web
urls = (
'/uuid', 'Uuid',
)
class Uuid():
def GET(self):
web.header('Cache-Control', 'no-cache');
return str(uuid.uuid1())
app = web.application(urls, globals())
if __name__ == '__main__':
app.run()