html5 - Writing an application to work offline (Web application) -


when writing application work offline , online best write once work offline , online mode work same offline?

for example lets see have typical shopping cart example. shopping cart contains items , customer.

when shopping cart loaded, should cache items + customers in local storage , use data cache both online , offline , update cache needed? best practices when developing offline/online hybrid web application?

writing web-app work in online/offline mode writing "normal" server-driven web app, exception have data access layer (dal) sits between app , data living on either server (on-line mode) or browser's data(offline mode).

depending on application , it's needs, can run in 1 of 2 modes: a.) cache-and-try-your-best mode or b.) load-everything-and-check-for-updates mode.

each of these 2 modes has , bad parts, , can have different parts of application lean 1 way or other.

cache-and-try-your-best mode

for mode, dal caches data server browser's data stores accesses data during it's normal course of operation. once in offline mode, dal tries it's best meet users' requests, has cached data work , operations may not able completed (or @ least not right away). on up-side, there minimal start-up time waiting data load, on down side, every action requires server hit (if connected) , data has cached. app has fail gracefully operation can't complete due incomplete data.

load-everything-and-check-for-updates mode

in case, dal loads of data app needs browser when app starts. if app has been loaded, of data has updated make sure cache isn't stale. in up-side, user doesn't have wait long things ever, since local operation, on down-side, if there lot of data, start-up time rather long.

in either case have battle stale cache issues, , issues persisting off-line operations server. means on start-up, , periodically while app running, need sync server keep cached data fresh, , share local-only state may have server rest of world sees updates instance of application.

persisting operations server occurred while app in offline mode can particularly tricky when data involved operation changes between updates of app. example, if cached bank balance out-of-date , indicates more money "true" state reflected server, user overdraw account without knowing it. extreme example, sort of operational collision detection needs in place handling updates may run each other.

in general, if have app both on- , off-line, write app app doesn't need care. lower-level data layer abstracts away of problems, , app needs know how deal not being able information wants (which app, on- or offline, should do).

for shopping cart, (or hopefully?) have way more products individual customer put in cart. loading of them everyone's browser huge waste of bandwidth , cause such delay users massive bandwidth cost , lost sales (due slow response times) sink business. load products browser data as-needed, , if want to, load other products "other users bought" associated items in cart.


Comments