Arun Sharma
Arun Sharma

Reputation: 517

What API to use for Offline Chrome App

I want to develop an offline chrome application.

As in offline app SQL is not available , so what API can serve the following purpose.

=>Large Storage

=>Efficient method to set and get values

=>Fast

=>Secured (user cannot temper the data)

Confused between IndexDB and File System API

I have knowledge of web languages and how online apps can store data on server. But don't know much about how to save data offline.

Upvotes: 0

Views: 515

Answers (1)

Pawel Uchida-Psztyc
Pawel Uchida-Psztyc

Reputation: 3838

It all depends on your needs. The Chrome apps have couple of limitations. Because they must to be very fast some web API's are disabled. You can't use localStorage and webSql for example.

However in apps you have different set of storage options:

  • chrome.storage.local - equivalent for localStorage but asynchronous. you can also save/read many objects at once
  • chrome.storage.sync - same as above but data are shared between different app instances (on other browser's profiles or machines)
  • web filesystem API - well known web filesystem API that can keep any kind of file in protected, browser storage. User's do not have direct access to this files, only the app have
  • extension to the above: chrome.syncFileSystem - it works similar to the above but files saved using this API are synced between app's instances (e.g. different machines) using Google Drive as a back-end. However user's can't see synced files in Drive UI because they are hidden.
  • chrome.fileSystem API - another extension to the web filesystem API and it gives you access to the user's sandboxed local filesystem. You can read from and write to selected by the user locations.
  • IndexedDB - quoting the docs: IndexedDB is an API for client-side storage of significant amounts of structured data, which also enables high performance searches of this data using indexes.
  • other custom solutions saving data on some server and syncing changes in all instances

You can choose one of above. As I can see you'll probably want to use IndexedDB API. It is not SQL and it is different approach to saving data. If you never use it before try some sample app first. However it's fast, efficient and combining with unlimitedStorage permission also can set large amount of data.

I also suggesting you to read Offline First page in Chrome Apps documentation where are examples of solutions for making an app offline.

Upvotes: 4

Related Questions