javascript - When to call the backend and when to store locally (angularjs) -


i have ionic app , parse.com backend. users can perform crud functions on exercise programmes, changing every aspect of programme including adding, deleting, editing exercises within it.

i confused when save, when call server , how data can held in services / $rootscope?

typical user flow below:

  1. create programme , client (create both on server , store data in $localstorage).
  2. user goes edit screen can perform crud functions on exercises within programme. perform server call on each function synced backed.
  3. the user may go , select different programme - downloading data , storing localstorage again.

my question how can ensure users data saved server , offer them responsive fast user experience.

would normal have timeout function triggers save periodically? on mobile amount of calls server quite painful on poor connection.

any ideas on full local / remote sync ionic , parse.com welcome.

from experience, best way think of follows:

  • localstorage cache layer, if date great because can reduce network calls. limited current session, , should treated volatile storage.

  • your server source of truth, , such, should updated.

what means is, reads, localstorage great, don't need fetch data million times if hasn't changed. writes, trust server long term storage.

the pattern suggest is, on load, fetch relevant data , save local storage. further reads should come local storage. edits, should go directly server, , on success, can write changes localstorage. way, if have error on save, user can informed, and/or can use localstorage queue continue trying post data server until full success.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -