Service worker improvements
-
@julian Would like to suggest two improvements in the service-worker of NodeBB before version 4(GA) is released-
- Web-push notification support. You open sourced the firebase plugin but that doesn't seem to be working.
- Offline caching of (one-to-one)chats.
May be I can also make a PR if you can guide me from where to start.
-
@julian So that means you will improve the firebase plugin and make it compatible with v4?
Apart from this also, service worker requires improvement. As far as I can see in current service worker, every GET and DELETE request is intercepted but nothing is cached which means that there are two requests for the same which is not required. So, while making the PR for caching chats, I can also fix this.
if (event.request.method === 'POST') { return; } event.respondWith(caches.match(event.request).then(function (response) { if (!response) { return fetch(event.request); } return response; }));
Please tell apart from
/api/v3/chats
which other paths need to be cached for chat to work offline. May this can be an optional feature and only those admins who want to enable it can do so from admin panel.
-
@julian Yes, that's what I also observed. But that leads to extra browser resource consumption. So, while making chats cacheable(openable while offline), I can address this also.
So, apart from /api/v3/chats which are the other paths I need to cache for the chat to open while being offline? -
Update: From https://github.com/NodeBB/NodeBB/issues/12235 it seems that there is no need to make changes in the core NodeBB and I can make offline chat as a separate plugin.
So, @julian @baris since you are well versed with the code, please tell which paths need to be cached for chats to open offline.
-
@bh4-tech with regards to the firebase plugin, it does still require use of a third-party software (that is, Firebase), which makes it difficult for some to use.
The plugin was originally developed for two reasons:
- The desktop notifications plugin was unreliable on mobile devices.
- Initial work for the plugin was funded.
However, after it was discovered that there was no compatibility with iOS, the funding dried up as we could not fulfil the client requirements.
That's where this plugin stands now, there is no financial backing to continue work on it.
However, looking into the MDN documentation, there is a new API that is finally getting broad adoption (as of 2023, anyway, so even better now): the Push API
It could be that this will finally allow NodeBB to natively support push notifications that work reliably even when the browser is closed.