Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XHR event for when response get updated #109

Open
hthetiot opened this issue Jun 4, 2018 · 1 comment
Open

XHR event for when response get updated #109

hthetiot opened this issue Jun 4, 2018 · 1 comment

Comments

@hthetiot
Copy link
Contributor

hthetiot commented Jun 4, 2018

Currently we use an event 'push' internally to update http2-cache Configuration.cache to last response and app need to perform new XHR to get updated content from cache.

I know that the clean way would be to shim SSE on http2-cache.js but that would required developer to change from XHR to SSE on their application also.

That why this issue is more for addressing the issue in term of XHR use case.

Note: the future way would be to have a http2-cache.js in pair with ServiceWorker and use push event

Note2: Another alternative would be to implement Fetch and Stream

fetch("https://www.example.org/").then((response) => {
  const reader = response.body.getReader();
  const stream = new ReadableStream({
    start(controller) {
      // The following function handles each data chunk
      function push() {
        // "done" is a Boolean and value a "Uint8Array"
        reader.read().then(({ done, value }) => {
          // Is there no more data to read?
          if (done) {
            // Tell the browser that we have finished sending data
            controller.close();
            return;
          }

          // Get the data and send it to the browser via the controller
          controller.enqueue(value);
          push();
        });
      };
      
      push();
    }
  });

  return new Response(stream, { headers: { "Content-Type": "text/html" } });
});

Note3: SSE ref https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events

@hthetiot
Copy link
Contributor Author

hthetiot commented Jun 4, 2018

Possible solutions:

  • Shim SSE (initial)
  • Add custom event on XHR push
  • Add service worker with push support
  • Shim Fetch and Stream
  • trigger XHR events again on push

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant