I have made a simple web app, which runs completely offline - all data is saved in HTML5's localStorage. Now, I want the data to get synced with the server, so that the user is able to use the app on multiple devices at a time.
What I have done so far is:
- For each operation the user performs, a log entry is added.
- When the user is online, all logs are transferred from localStorage to PHP through AJAX.
- Corresponding changes are made in the SQL Database.
- All logs are deleted from the localStorage.
So, all the localStorage data is getting "backed up" on the server properly.
Anyhow, changes made from one device is not being reflected to the other device and vice-versa, to do this, we would have to get some data from SQL to the localStorage.
Now, my question is as to what will be the appropriate and best way to do this?
After the four steps above, do I
- Clear all localStorage data and save the SQL data into localStorage.
- Keep a log of changes made in the database, and do them on the localStorage.
- Any other approach.
Also, what about timestamps? What if there are conflicts?