DEV Community

Discussion on: mobile local web-server to store local data by a web app

Collapse
 
rhymes profile image
rhymes

Hi Nando, I agree you should move away from the AppCache, mostly because it has been deprecated and it's going to be removed.

A possible alternative for offline usage are service workers as Jaaki suggested, though I admit they are more complicated to use. A few resources:

So this might be option 1, re-implementing the AppCache code with Service Workers.

Option 2 might be using something like AWS AppSync that lets you sync your app for offline usage:

AWS AppSync supports an offline programming model where application data is not only available offline, but users can add and update data as well. When the device is offline, the application UI will be automatically updated with the offline data. AppSync lets you define how data is cached offline as well as how AppSync should manage the cache updates under different network conditions

Option 3, as you suggested, would be embedding a web server, like nanohttpd I guess but how do you sync data from the local copy to the upstream server? What happens if the local web server process crashes? Do you have any guarantees? I'm not familiar with Android development so I might be raising problems that are not problems indeed.

Regarding storage: if you use a service worker you can use IndexedDB through localForage or PouchDB, if you use AppSync they store your data (I believe it's inside Amazon DynamoDB) remotely and locally, if you use an embedded webserver you can probably use Android's own DB storage libraries.

Hopefully this helps clear some doubts

Collapse
 
fc250152 profile image
Nando

Hi friend, thank you so much for your comprehensive and exhaustive explanation.
I will study carefully each of the options you have exposed.

Only to better define the scenario already in place:

  • the app in the browser receives from the main web server one or more "documents" to complete offline, then transmits them back to the same server when they are ok.
  • in order to work offline, the app uses the AppCache for the pages and the LocalStorage to store the data.
  • the data are stored in a different format with respect to the one that they have in the main server: an "internal" format, known only to the front-end app.

In the "new scenario" I would give up both the AppCache and the LocalStorage, and possibly also the other limitations imposed by the browser by "proxing" data operations to a local (pseudo)webServer.
That's all.

Many thanks for your help!
Have nice days
Nando

Collapse
 
rhymes profile image
rhymes

I think you could go incremental with this thing. First use localForage or a similar option so that you can abstract from localStorage and maybe use IndexedDB. Then you can look into replacing AppCache with Service workers.

If that it's not enough then you can write all the code to proxy the webserver.

I'm just saying this because that option seems the most complicated and the one with the most code, while you can maybe settle to not having a proxy at all.

Have fun!