Request Deferrer

This recipe shows how to enqueue requests while in offline in an outbox-like buffer to perform the operations once the connection is regained.



Use Case

As a modern framework developer, I want to provide an agnostic way of handling requests while offline.


Use a Service Worker to intercept requests. While offline, record the successive requests in a queue to preserve the order and answer with fake responses. If online, flush the queue to replay the session and sync with the server.

This advanced technique is intended to integrate with REST APIs and it requires the client to deal with asynchronous create (POST) operations (HTTP answering with status code 202, Accepted).

The solution is a proof of concept and does not include error handling which is a real challenge in this implementation. Some of the problems are stated in the inlined documentation.


Beyond Offline

Has it been useful?

Tell us what you think of this recipe by leaving a comment!