Open dpwspoon opened 7 years ago
Possible options
Before (A) - schedule repeating XHRs at fixed interval
var sendXHR = function(...) { var xhr = new XMLHttpRequest(); ... xhr.send(""); }; window.setInterval(sendXHR, 30)
Before (B) - chain next XHR after previous XHR
var sendXHR = function(...) { var xhr = new XMLHttpRequest(); ... xhr.send(""); xhr.onload = function() { ...; setTimeout(sendXHR, 30); }; };
After (1)
var sendXHR = function(...) { var xhr = new XMLHttpRequest(); ... xhr.oncachechanged = sendXHR; xhr.send(""); };
After (2) - defers response when previous answer already known
var sendXHR = function(...) { var xhr = new XMLHttpRequest(); ... xhr.setRequestHeader("Prefer", "wait=30"); // RFC 7240 xhr.send(""); xhr.onload = function() { ...; sendXHR(...); }; };
Possible progress event use case. Source: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType
Possible options
Before (A) - schedule repeating XHRs at fixed interval
Before (B) - chain next XHR after previous XHR
After (1)
After (2) - defers response when previous answer already known