Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sync indexedDB local data with Server?

Tags:

indexeddb

I have a small project which stores data in IndexedDB in browser. I would like to add sync functionality so users can access the data everywhere.

How can I sync local IndexedDB data in a remote server or server database so I can access it everywhere? In other words, I would like to make this demo available in all of my browsers. (Security is not a problem in this phase)

like image 728
pmoubed Avatar asked Oct 21 '12 18:10

pmoubed


1 Answers

In fact, there is not much on IndexedDB for synchronising database. You only need RESTful service for replicating from server to client and vice versa.

For effective synchronization, the service should support etag (HTTP spec) for each record, updated (ATOM spec) for collections. Additionally to support resumable update, totalResults, startIndex, itemsPerPage (OpenSearch spec) and ordering by updated is necessary.

When GETting a record 'If-None-Match' header of etag is specified, to get full caching benefit, When PUTting a record 'If-Match' header is specified to resolve conflict on client side. To update the collection, query is limited by updated parameter, so that only records not in the client database are returned.

That is how I attend to implement on my open source IndexedDB API wrapper. See example app https://github.com/yathit/feature-matrix in angularjs and demo.

Also look at PouchDB.

like image 77
Kyaw Tun Avatar answered Oct 01 '22 12:10

Kyaw Tun