-1

I have the following challenge: - I'm trying to save website data to local storage on end user systems. So that they can work while offline. I would furthermore like the local cache to be available for as long as possible. Like somehow handle/block ctrl-r and F5, so that the cache is not flushed. This because the users will be working in the field and will very likely not have access to the Internet.

I have looked at several options. Right now I'm debating with myself over using IndexedDB or the File API.

-Cons on the File API: It seems to be deprecated: http://lists.w3.org/Archives/Public/public-webapps/2014AprJun/0010.html

-Pros on the File API: Write to the filesystem instead of internal browser cache

-Cons on IndexedDB: Browser controlled cache

-Pros on IndexedDB: Still live. Nice key/value db.


I also tried LocalStorage in browsers. Read this: Storing Image Data for offline web application (client-side storage database) - especially the PouchDB thing is nice. But! If the user clears the cache before a sync can take place = data loss :-(


I'm hoping you can give me some good advice. I'm looking forward to hear from you.

Thank you very much. /Lars Bingchong

Community
  • 1
  • 1
Lars Bingchong
  • 323
  • 3
  • 12

1 Answers1

0

The last update to the W3C spec for the File API was made on 15th July 2014 - just two weeks ago at the time of writing. There's no mention there of the API being deprecated. In fact, the wording specifically refers to a 'work in progress'. The MDN reference also makes no mention, but is hedged around with caveats about the specification being subject to change, use of prefixes, etc.

Depending on your exact requirements, LocalStorage is good up to about 5Mb, and IndexedDB builds on that with additional facilities for search & query.

You'll also need to ensure that your code and other assets are available offline, so you'll need the application cache for that. Applications stored in the application cache will run online too, so there's no conflict there. The browser takes care of updating the local copies whenever it finds that the manifest has changed.

If you're concerned about data loss there's little you can do offline except ensure the the user knows they shouldn't do things that delete their data. In that regard it's much like any other native application. You could look at the insidious Evercookie as a possible storage medium that might help, but use it with care.