Why use fetch alone?

ยท

2 min read

When working on local projects that usually involve fetching data, the common go-to guy for this lately is the fetch api. Well recently, I noticed how much defects that come with shipping a production app just with the use of a fetch api.

Let me list the obvious :

  • fetch does not have a specific timeout option. By default different browsers determine when best a fetch timeout.
    In fact, the timeout for one of the leading browser is 300 seconds ๐Ÿ˜ต

why it matters

If you have ever stayed in some region with bad network speed, you would appreciate that some fetching can last as long 200 seconds.

In cases like these, your fetch might really have to wait for as long the browser allows, even for 300 seconds ๐Ÿ™Š. I shouldn't be saying any more, but for a user this is hell.

As a developer a way to at least notify our users is to set a timeout. So that at worse cases, the user might have to shift to a place with a better speed ๐Ÿ˜‚.

What can I do

Make a wrap around your fetch and never ship to production just with the common way we use fetch api. This article has it all spelt out or rather still use axios or any other third party library built around fetch api.

Thanks for reading through. This little information saved me a lot of stress accompanied with a production app I did sometime and I hope it helps you too.

ย