-
(Best start) Merge message-bus requests across multiple open tabs on the same Discourse forum.
The message bus is what Discourse uses for all of its live updates. However, currently, every tab you have open makes a request to the server every 15 seconds. A ServiceWorker can intercept these requests and merge them all into 1 request every 15 seconds.
-
(Questionable value) Force caching of vendor.js and application.js
This probably isn't worth the effort. The JS files have the SHA hash of their contents in their name and have aggressive caching headers.
Pretty much the only beneficial option here is to instantly reply to any request containing If-Modified-Since
with 304 Not Modified.
-
(Great value) Push & Mobile Notifications
Because a ServiceWorker is able to run even when no clients are around, it's required in order to serve push notifications. Also, because we know there should only ever be one (or less) ServiceWorker at a time for each forum, it's the ideal place to serve desktop notifications from. This will let us disable the buggy "active tab tracking" code currently in use for desktop notifications.
Chrome push notifications require the forum admin to create an application with GCM (Google Cloud Messaging). Firefox push notifications require server-side storage of magic URLs.
-
(Easily screwed up) Caching of topic & post data
The ServiceWorker could use IndexedDB to store post data previously requested from the server, and reuse known posts in the responses when scrolling through a topic, potentially allowing offline topic browsing. However, this is easy to mess up - currently, messages are not delivered on the bus for every post that is edited or deleted; and if the message bus backlog gets cleared, the cached post data could easily be stale.
The stale cache problems could be alleviated if we use Background Sync, but it's just at a proposal stage right now, not implemented in any browsers, and the spec is a bit sparse.
This is probably best shelved for a later date.
-
(Best value, hardest) Deliver the entire initial load from local cache
This would be the most ambitious thing to do with ServiceWorkers. The layout of the initial page is largely predictable, and could be stored on the client. If no PreloadStore data is provided, the Ember router will just do a network fetch for the data. Combined with caching topic & post data, this is a recipe for a fully offline initial page load. We would save a lot of network bytes by doing this (check out that <noscript>
section in every initial-load of a topic view).
However, this rears the ugly head of one of the hardest problems in computer science: Cache invalidation. When I look at the source of meta.discourse.org, I see tons of site settings that can be changed, the site can update and so the script hashes change, the current customizations can change, data about groups and categories ( see https://meta.discourse.org/site.json ) can change, the custom emoji too.
The good news is that that's about it for the list, though. We can add in live updates for categories, emoji, groups, and the site settings. We can make customizations refreshable in the background (sometimes). (We'll have to move script customizations out of </head>
and to a file like the CSS is.) If we get all that, the last thing left is updates to the site. And a full network refresh is probably OK for that.
Reply with comments, or if you have any use-cases that I forgot about.