davidbaguetta
davidbaguetta

Reputation: 532

Should I wait for server response or update client straight away?

So this question just popped up in my head today. I am working on an SPA using Angular and I'm developing this calendar module (think Google Calendar) where the user can add, edit and remove events.

I wonder what your opinions are on not waiting for the server after an action takes place. For example, if the user decides to add a new event, the moment he submits the form, a HTTP request is sent to the server to add that event to the DB and return a response. Initially, I was subscribing to the server response and once received with success, I updated the UI with the new event. But then I changed the code so that after the user submits the new event it is first updated in the client side and the UI and only then does it send the request to the server.

This obviously has the risk that if something goes wrong for some reason in the server, it can be frustrating to provide the user a warning and removing his event again after adding it. But the chance of something going wrong is extremely minimal. If the update is done on the client straight away, the user receives feedback much faster, thus making the application much more seamless and fast to use.

I actually went and opened Google Calendar on my browser and noticed they do the exact same thing. Any action performed on an event has instantenous feedback and at the bottom of the page a little popover appears saying 'saving...' for like half a second and then shows 'Event saved!'. What do you guys think about all this and what are the pros and cons of each approach?

Upvotes: 1

Views: 457

Answers (1)

Raed Khalaf
Raed Khalaf

Reputation: 2065

Its all about the request isolation

i.e if the request depends on other requests.

lets consider a messaging system, it has groups and users sending messages.

  • sending messages: obviously, updating the view while the request is on fly has v.good user experience, and let the user send many messages in parallel, i.e sending messages without waiting for the previous messages, simply you can add a small spinner to each message indicating its state:

enter image description here

  • Creating groups: in this case the normal user can create groups and invite users to it, the request of creating groups cannot be reflected on the UI while the request is on the fly, because in this case you can send message to the the group which is not created yet.

Upvotes: 1

Related Questions