g105b / pwa

Example of how to turn a PHP website into a Progressive Web App.
https://pwa.g105b.com
88 stars 41 forks source link

tentative plan for implementing offline support? #5

Open jantech opened 8 months ago

jantech commented 8 months ago

Hi,

Do you have plan for implementing below offline support features mentioned?

Thoughts and to dos:

  1. How can we capture form POSTs when offline, to send them when the network comes back up?
  2. What's the best way to prevent certain user actions when offline?
  3. How can we disable caching on certain URLs? (Useful for lazy loading quick-changing content).

Thanks

g105b commented 8 months ago

Hi @jantech ,

Yes I do have some thoughts, and one day I will get around to implementing them. All of the above can be achieved with the service worker. At the moment, the service worker will respond with the latest cached page when offline, but it does this without applying any logic.

We can add some logic to the SW that takes a POST request and adds it to a queue for later processing. Then when the SW detects that the network is online again, it can send the requests to the server and update the client with delivery status.

This is easy to type up my ideas, but I'm aware that in the real world there are many scenarios that need to be covered, and I don't want to implement something half-baked.

I will revisit the to dos on this project in time, but at the moment I am too busy with paid projects to invest my time into things like this.

More reading: the fetch event can be intercepted whenever the browser makes a new network request. the actual Request object can be cached/queued, and then dealt with when the network status changes.

Hope the links help show you my plans. If you feel like contributing any changes, I'm happy to help guide you, but at the moment I can't commit any time to the project.

jantech commented 8 months ago

Thanks @g105b , for your reply.

Looking forward for the To Dos get implemented. will be waiting for the updates.

Thanks, Jagan

eren-cantemur commented 8 months ago

Would love to talk about ideas on the topic. We also need the offline support and we are trying to come up with a way.

g105b commented 8 months ago

Hi @jantech and @eren-cantemur - this is something that I'm currently working on. Catching the requests from a form while offline, so it can be sent to the server when back online.

Trying to keep it simple and generic so it can be applied to any project.

I'm currently working on another project but as soon as I get time I'll finish this idea off.