This question is about HTML5 offline apps. This answer is from 2009 about regular web pages.
I have a heavyweight HTML5 PouchDB offline app. It's an AngularJS app, that writes to/from a PouchDB.
The app needs to handle multiple tabs without help from the server.
If a user opens my app in two tabs, they'll create a race condition.
1. tab1 opens docA and edits
2. tab2 opens docA and edits
3. tab1 saves docA
4. tab2 saves docA (overwriting tab1's changes)
My app needs to gracefully handle this, but how?
Some ideas:
- Prevent multiple tabs of the same app.
- I haven't found a graceful solution for this.
- Get change notifications from PouchDB from onChange
- Will onChange fire in another tab?
- This doesn't solve the problem, just exposes it sooner.
- Use different PouchDB's for each tab, sync between them.
- Doesn't solve the problem, just makes it a Sync problem.
- Seems like alot of memory.
- Document Locking
- Complex onBeforeUnload
- How to recover from tab crashes that don't unload correctly?
- Browser-tab IPC.
- When opening a doc, ask other tabs if they have it open.
- The best I've found is using localStorage
- Something I haven't thought of yet.
Any suggestions?