DEV Community

Discussion on: Is there any pattern for handling network error when sending requests?

Collapse
 
rhymes profile image
rhymes

I also thought about the Cache API but I wondered is there any tool of pattern or does someone already implemented it on his app.

Isn't that what the service worker does? Using the cache API

So If I understand correctly, and I managed to see this behavior when I worked on a service worker library, on Chrome I notice kind of an exponential time for retries when I shut down my network and register cache strategies on my web page. Interesting.

Exponential backoff for retry strategies is a good way to avoid flooding the upstream server. If the server is telling you "I'm having issues", flooding it with a request every N milliseconds it's not going to help the server (you end up creating a denial of service) nor the user experience (too many requests and errors to show)

Thread Thread
 
anwar_nairi profile image
Anwar

Yes exactly, the service worker is taking advantage of the Cache API to handle network issues, you only need to implement the algorithm or use Workbox.js.

I guess exponential retry strategy is good. I wonder if there is variants like "up to a certain number of retry" etc... Really exciting, thanks to Service Workers we are closer to native app experience! I hope others browsers will support the Background Sync API soon!