javascript - Should I pull from the server or just update the view? -


using ajax on website, make changes data through view. send data server it's saved. steps outlined below:

  1. user changes data on view.
  2. javascript triggers.
  3. before ajax call
  4. ajax call. server saves data.
  5. after ajax call

my question is: better, design-wise, update view in step 3 , update data , let data potentially out of sync until refresh or make ajax call, return data server , update view in step five?

i have first option implemented since little easier , "flowed" me better, second 1 seems better, since user up-to-date data server.

this availability vs consistency. depends on whether want more available or consistent. happens if goes wrong , information couldn't updated in server side, users angry? or maybe users angry if cannot see right value of content? have decide 1 or another. article situation consistency vs. availability: eventual consistency werner vogels


Comments