P.Brian.Mackey
P.Brian.Mackey

Reputation: 44275

HTML5 - Web sql setting up offline storage

How do I setup the basic switching of offline storage modes (offline/online) in Web SQL? I know there's javascript

window.navigator.onLine. I can check the mode and then go through a process...

//All GET/POST performed with AJAX
//On Startup pulldown entire accessible database into offline storage (Doesn't seem secure IMO)
//if(read) pull from offline
//if(create, update, delete and online) pull from standard db, mark changes with offline expiration flag
//if(create, update, delete and offline) perform operation on offline storage, persist with POST when next online (change flag)

I'm asking if there is any OOB integration for these standard tasks?

Upvotes: 0

Views: 478

Answers (2)

robertc
robertc

Reputation: 75707

The navigator.online property generally isn't very useful - in a desktop browser all it does is hook into the File -> Work Offline menu. It may be more useful on an iPad, I don't know because I don't have one, and I'm guessing there's not a File menu, but I would recommend you test.

A common approach to this issue is to set up two easily distinguishable files in the fallback section of your manifest. Every time you want to connect back to the server attempt to fetch the file with AJAX and, in the callback, check it to see if you got the online file or the fallback, then branch accordingly.

Upvotes: 1

wesbos
wesbos

Reputation: 26307

You shouldn't be using Web SQL as that spec was nixed a new months ago. You should be using Localstorage. Unless you are specifically coding for something like the iphone, but even then you dont know how long the spec will be in webkit.

Upvotes: 0

Related Questions