Retry XMLHttpRequest Carefully
It's rare to see a web app that doesn't use XMLHttpRequest (or fetch, the new API with comparable capability). XMLHttpRequest (which we can call XHR if you're into the whole brevity thing) is as handy as a shirt pocket, but it doesn't do much to encourage robust and resilient programming practices. Any app that runs in the real world will sometimes encounter transient network interruptions and server outages. We should gracefully recover from both by automatically retrying our requests. But, we shouldn't turn a brief server hiccup into a full-on fireworks display by retrying too fast or by having every client retry at the same time.
This good advice gives us three concrete goals:
- Retry our XHR when we get an error.
- Pause an appropriate duration before retrying.
- Randomize the duration of the pause.
Source: Retry XMLHttpRequest Carefully, an article by Aaron D. Parks.