Generally handling HTTP timeout, failed requests etc


The irony of this connected age is that one thing that is complicated is when connection is lost and similar. Most users are on mobile and we try to make our web app look and behave like native apps.

What is your recommendation on handling flaky connections? Do you write code to retry? Do you just let it fail and hope customers try again?

Service worker?

Any strategies or tips would be much appreciated!

This is what service workers are for. However that does mean writing JS and not Elm. If that’s a concern, or if you just want another approach you could use the online and offline events to detect when you gain and lose connection and handle it in the main thread. I’ve used those before when I had to target older browsers that didn’t support service workers.

1 Like

There are other options too depending on what you’re trying to do with offline support. There are projects like GitHub - jlongster/absurd-sql: sqlite3 in ur indexeddb (hopefully a better backend soon) if you want a performant DB in the browser, as well as many other libraries for handling disconnecting and reconnecting.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.