ElkArte Community

Elk Development => Feature Discussion => Topic started by: Spuds on March 26, 2024, 08:32:59 pm

Title: PWA Progressive Web App
Post by: Spuds on March 26, 2024, 08:32:59 pm
I've been working on adding this feature to 2.0 and its now it is available for testing.

To make this work, the following things were added to elk20


You can enable just the manifest file, which some devices use to create better shortcuts. 
If you enable the PWA (you must have manifest enabled as well) then you can "install" the app, which will look mostly like it does in a browser tab when opened, but you can place the app on your desktop or home page or .... and then launch it immediately since the landing page is in the cache (network first with cache fallback)

I chose to employ a cache based PWA, so the app will cache static assets like CSS and JS, it will also cache Images, and lastly it will cache the site landing page and the offline page. 
There are several automatic maintenance functions which prevent the cache from growing to large.  It will also remove the app / cache when you disable it in the Admin panel.
It will clear the app cache when you clear the cache on your site. 

There are several cache strategies that our service worker uses.  Some assets are network only, others network with cache fallback,  others are cache first with network fallback and some are cache first with a network fallback/refresh. I went back on forth if to even use the cache and then how to cache items so this may change and also why there are so many types.
It also employs preload capabilities for best performance on fetch events.

I've only installed the "app" on a couple of devices, so I'm sure there are going to be a few bugs to work out as testing progresses.

For those familiar with the development tools built into browsers, you can see/monitor the service work and its caches
Title: Re: PWA Progressive Web App
Post by: Burke Knight on March 26, 2024, 09:38:11 pm
Quote from: Spuds – I've been working on adding this feature to 2.0 and its now it is available for testing.

Hmm... I remember a while back I suggested something like this, since I learned and PWA'd all my sites.
Nice to see that it'll be in the admin panel to set up. A lot simpler than making the manifest.json file and adding the code to the index.template file. :)
Title: Re: PWA Progressive Web App
Post by: Spuds on March 27, 2024, 10:29:14 am
The admin interface makes creating / updating the basic manifest easy, but a manifest w/o a sw.js is ends up as pretty shortcut/bookmark.  I allowed for that option as that is all some sites may require.

Adding in a functional service worker allows one to install it, like an app from the play store, gives you some extra SEO points.

I went from a simple sw.js shell that simply allowed it to register/install/activate but really did nothing .... to what I currently have for testing where I make use of a cache so the app will at least launch a homepage even if you are offline, and then "complain" about being offline. 

Since a forum tends to be all dynamic content, its difficult to have an offline experience where one could potentially reply while offline and have it post when your network comes back, stuff like that, but that would be a large project just on its own  :shocked:

Anyway, hope folks test it out.
Title: Re: PWA Progressive Web App
Post by: Burke Knight on March 27, 2024, 11:07:00 am
Installed and working for me, on my phones.
Only issue I have, the green background on loading screen could be different.  :tongue:
Title: Re: PWA Progressive Web App
Post by: ahrasis on March 27, 2024, 11:24:26 am
Quote from: Spuds – Since a forum tends to be all dynamic content, its difficult to have an offline experience where one could potentially reply while offline and have it post when your network comes back, stuff like that, but that would be a large project just on its own   :shocked:
If member is offline, keep it as a draft instead?
Title: Re: PWA Progressive Web App
Post by: Steeley on March 27, 2024, 11:34:12 am
Quote from: ahrasis –
Quote from: Spuds – Since a forum tends to be all dynamic content, its difficult to have an offline experience where one could potentially reply while offline and have it post when your network comes back, stuff like that, but that would be a large project just on its own   :shocked:
If member is offline, keep it as a draft instead?


If you are offline, you should take advantage of that, turn off the borg tether ..

(https://media1.giphy.com/media/d1Hrg00RXt3dfaFO/200.gif)

.. and go play!
Title: Re: PWA Progressive Web App
Post by: Spuds on March 30, 2024, 10:35:47 am
Quote from: Burke Knight – Only issue I have, the green background on loading screen could be different.
Indeed~(https://media3.giphy.com/media/l52CGyJ4LZPa0/200.gif)
Title: Re: PWA Progressive Web App
Post by: Spuds on March 30, 2024, 11:51:26 am
Quote from: ahrasis – If member is offline, keep it as a draft instead?
Right now the draft is server dependent ... however we could save it to the PWA cache when offline.   Something to consider for the future as enhancements are made to the PWA.
Title: Re: PWA Progressive Web App
Post by: ahrasis on March 30, 2024, 07:41:07 pm
So, if member is offline, keep it in PWA cache, but when he is back should it immediately be posted or prompt him whether he wants it to be posted or discard it?
Title: Re: PWA Progressive Web App
Post by: Spuds on March 31, 2024, 03:32:23 pm
I was thinking that if offline and they hit POST then it would show a message such as "You are offline, would you like me to send the message when the connection is restored" or something like that.  Otherwise it would stay as a draft, and maybe push the draft when the connection is restored.
Title: Re: PWA Progressive Web App
Post by: Steeley on March 31, 2024, 05:38:18 pm
Quote from: Spuds – I was thinking that if offline and they hit POST then it would show a message such as ......


"You are off line - click 'save as draft' then turn this off ...
....and go play!"


{sheesh, you thought I was making funny?} 🙄

😛

Quote from: ahrasis – So, if member is offline, keep it in PWA cache, but when he is back should it immediately be posted or prompt him whether he wants it to be posted or discard it?

No auto-post... but maybe a pending message flag.. invariably events will overcome the post in the meantime, the poster will think better of it, and go to edit/delete it only to discover that at some point while playing the connection was re-established and the (now outdated/unrevised) post was sent unknowingly..🤬
[/quote]