If Firebase is online at the beginning and temporarily loses its connection and then reconnects, it will synchronize local data. Therefore, in many cases when Firebase is online, you can simply continue to insist on Firebase during the crash.
For real-time use, you probably want to monitor the status of the device, and also watch .info/connected to know when Firebase is connecting.
new Firebase('URL/.info/connected').on('value', function(ss) { if( ss.val() === null ) else });
A way to achieve this with the current Firebase toolkit, until it supports true offline storage, would be
- keep local data simple and small
- when the device connects to the network, convert the locally stored data to JSON
- use
set() to save data in Firebase on the appropriate path.
Also, if the application loads when the device is offline, for some reason you can “just start” Firebase by calling set () to “initialize” the data. Then you can use Firebase as usual (just as if it were online) until it appears on the network at some point in the future (you will also want to keep your local copy to deal with the case when it never does not work).
Obviously, the simpler the better. Simultaneous changes, local storage size restrictions, and many other factors quickly accumulate to make any stand-alone storage solution complex and time-consuming.
Kato
source share