kaazing / http2-cache.js

2 stars 11 forks source link

SSE API to see when cache is updated #46

Open dpwspoon opened 7 years ago

dpwspoon commented 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(...); };
};
hthetiot commented 6 years ago

Possible progress event use case. Source: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType

screen shot 2017-10-23 at 3 25 48 pm