- getting the app to load while offline: I'd recommend using Workbox to help generate the Service Worker and to more easily handle caching.
- getting the app to work offline: you'd have to store data locally, use IndexedDB, through Elemental2 directly, or possibly find some lib that wraps IndexedDB with a more friendly API (I've had some success with Jake Archibald's idb, in a non-GWT project); and/or possibly the Cache API (it's available to GWT in elemental2-dom)
- detecting when you're offline or online: I've had some success with navigator.onLine (mapped in elemental2-dom) and the online/offline events, but it's not enough; there are times when the device thinks it's online but cannot talk to the server, so you need to deal with network errors.
Once you have that, you need to have a plan for what to do when you're offline and get back online: park requests and then replay them? Write data locally (e.g. a "draft" entity) and then synchronize it? If data is read/write, how do you deal with other users having changed the data while you were offline? (this is a problem in all applications, where things could have changed between the moment you load the data and the moment you want to store it back after a modification; but it's exacerbated in the case of offline apps). This is probably the hardest thing to get right, and it's highly application-dependent so I doubt you'll find anything but "patterns" to apply. I'm fortunate that the app I've been working on is "append only"; coworkers have worked on apps where the data can be locked server-side so nobody else will modify them, but it's not always possible. In any case, I think that means putting all your data access in a "data layer" that's responsible for getting it from either the network and/or IndexedDB and handling changes while offline, and whatever is needed when going back online; so your app will no longer directly do GWT-RPC, but delegate it to that data layer.
Last, but not least, you have to deal with app updates: when your app launches, it'll likely launch with the version it last "sync'd" and will retrieve the new version in the background. This means that old app versions need to be able to talk to the server, or at least detect that it's not possible. GWT-RPC is not your best friend here, as backward compatibility is possible but not that easy to achieve and mostly undocumented. And you then have to decide what to do when the new version is ready (that's the easy part though): display a notification in the app? force-reload it? do nothing and only use it next time?
Oh, and I almost forgot: how about authentication?
On Sunday, February 14, 2021 at 7:35:13 AM UTC+1 Amir Norozi wrote:
Hello every oneI created DWProject with GWT and need to work offline when internet connection lost.How can i use PWA to achive it and some RPC services exist in project and wanna when internet connection is back, they services automatically call and every thing will be done.thanks.
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to email@example.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/6fe4d733-edc8-48ed-8800-9d01dd1c5b75n%40googlegroups.com.