Online/offline data updating mobile best practices - javascript

I have a requirement to create a mobile app that has the ability to queue up records that need to be saved when no internet connection is available and update the data via web api when a connection is available in our SQL Server DB.
I'm trying to avoid having a local version of the DB on the device which I've seen some others recommend in other questions on stackoverflow.
The approach I'm going with right now is to try and save the records in a local store (JSON) while there is no connection. Then to try and hook in some event to know when the connection has been re-established to update my data to SQL Server.
I'm just wondering what the best practices are around this? Are there issues with my current way of trying to solve this problem?
We are using DevExpress's DevExtreme mobile solution with Visual Studio 2012 and Cordova PhoneGap.
Any advice would be very much appreciated.

How big is the JSON data that you want to store, likely to get?
Depending on your answer, you could store it (the JSON data) in localStorage and then write it next time the device is connected.

Related

React Web V9 Firebase real-time database caching/offline

I have a requirement in a react project to use firebase real-time db and sometimes this may be during low or no connectivity.
I know that Firestore has a native offline capability but just wondering how could I make firebase db work offline.
The requirements have quite a heavy R/W workload, so I'm trying to avoid Firestore in this instance.
Should I use something like indexeddb? Has anyone had anything similar? And regarding client side rest data encryption would you recommend something?
Many thanks
There is no built-in support for persisting data between reloads in the Firebase Realtime Database SDK for JavaScript/web. It does handle intermittent loss of connectivity, as long as the user doesn't reload the page.
If you want to persist data between page reloads, you will indeed have to implement that yourself - for example by storing the snapshot values in indexeddb.
Also see:
Does Firebase JavaScript API catch-up with server when re-connected

Saving Firebase RTDB bandwidth by performing initial sync from JSON file

Firebase Realtime Database offers powerful synchronisation across clients... But it does seem to have rather high bandwidth charges.
I was hence wondering if it is possible to perform an "initial sync" on clients, so to speak, where we load a reasonably recent version of the database from elsewhere (with lower bandwidth charges), and then have the Firebase SDK (flutter, web) sync from there instead of downloading all the required parts of the database. Maybe a "load from JSON" sort of function or similar.
Seeing as to how the Firebase SDKs do seem to store some state locally on clients (for offline operation) and sync up with Firebase once online again, I was wondering if it might be possible to:
set the local state to our "recent version" downloaded from another source, along with that version's timestamp
trick the client SDK into thinking that we are recovering from an "offline" state
then let the SDK communicate with the Firebase server to get changes since our last timestamp
Are there any approaches to achieve the effect of saving bandwidth through performing an initial sync from a cheaper source? Thanks in advance!
Unfortunately every get() and every realtime listener will load all data it needs from the database. I had the same idea when started working with the Firebase RTDB but unfortunately at this moment it's not possible.
The only way to reduce the bandwith is to read data in smaller chunkgs as possible.
You might want to take a look at AceBase, which is an open source alternative for the Firebase RTDB. It offers the same functionality, has powerful indexing and querying options, offline support, synchronization etc. Easy to setup and you can host it anywhere you want. You can even use it as a standalone realtime database in the browser, so you could also use it in combination with Firebase to perform custom synchronization between your front and backend db's. AceBase is free and its full source code is public.

How to create a database to store logs using phonegap?

I am dsigning an app for iOS using phonegap. What I want to do is log down the date and time each time when the user pressed a button on the screen, and be able to view the log on device screen with an admin access. I know I have to create some sort of a database to store the info, but can someone give me an example on how to create one as I'm new to phonegap and not sure how to do that.
In my opinion the best SQLite Plugin for saving a lot of data is this plugin:
https://github.com/brodysoft/Cordova-SQLitePlugin
There is no limit of storing. In this post How to compact SQL instructions in Cordova? I have written how to compact SQLite instructions, so you have not all this event overload.
But do you really want save every tap? That will be a lot of scripting work.
It seems as localStorage would be sufficient for your problem. You can simlply Json.stringify your data and put it to the local storage. Later get it from there and json.parse it. No phonegap needed just pure html5. Try search for localstorage HTM5

Best way to get and store data (optimized) to mobile app (Ionic, Cordova/Phonegap)

I want to do an app with ionic framework and cordova for Android and iOs and I want to optimize at most the requests to the server.
I need to get data from php server (API) and store in the mobile phone, this data is related, so I think that a SQLite is the best option to store it in the device because of to show it is more fast to do a complex SQL than get a JSON stored in localstorage (for example) and search and link the data in the mobile. I'm right?
I need to do this and can do a Pull to refresh in the app and get only new data.
I've been watching some solutions but I don't know what is the best.
Parse/Firebase: This is difficult to administrate for non-specialists, for this I have a backend to enter and modify data with the relations easily. In addition this services return a JSON with more data that I need.
Persistence.js and Persistence.sync.js this works with mysql-server and sqlite-local but can I sync only one table or get only the new data? And I did't find a solution for php server.
CouchDB and PouchDB: I don't know if this can be sync only for a new records.
Receive data in JSON and store it in SQLite: I need to create functions to do this easier.
Any other solutions?
I'm very lost in this topic.
Thanks!!
CouchDB and PouchDB: I don't know if this can be sync only for a new records.
That’s the default. Plus they handle all the nasty sync details for you. Would highly recommend looking into this.

how do I store data into database using javascript

I am using Google Map API to do address translation(mainly by geocoder).
And I'd like to store results into local database for future use since google map has a limit on total query number and frequency.
But how? I have googled and found an ActiveX based solution. Is there platform independent alternatives?
To access a database you are going to need a server side language. JavaScript can talk to PHP through AJAX and PHP can update the database with whatever parameters you give to it via JavaScript.
I would stay away from ActiveX as it can be tricky and you just dont need it.
When you have a database setup, have a look at these websites
http://www.tizag.com/mysqlTutorial/mysqlinsert.php
http://api.jquery.com/jQuery.ajax/
Current in-browser database options include IndexedDB, Web SQL, and Web Storage.
Browser support, however, isn't all that good. Web Storage is your best bet, but it won't work on IE7 and earlier.

Categories