piratdavid inquired whether Discourse’s instant live updates for the ‘latest topics’ page rely on frequent AJAX polling or a more efficient method like WebSockets. angus clarified that Discourse utilizes a custom message bus (available in a separate repo) rather than simple timeouts, directing the user to subscribe to this bus for real-time updates. gdpelican further explained that the MessageBus is implemented using long polling rather than WebSockets, where requests are held open by the server until new data is available. After the initial explanation, piratdavid asked if it is possible to stop subscribing to specific channels when navigating away from a page. gdpelican confirmed that unsubscribing is fully supported and provided code examples demonstrating how to use messageBus.unsubscribe() to stop listening for specific topic events, allowing developers to dynamically manage subscriptions based on the user’s current view.
I have written a plugin that has a news feed with a lists of latest topics in a sidebar. It updates regularly by making an ajax call to /latest.json every few seconds. The existing latest page in the forum has the same kind of functionality but the update is instant when something is posted. Is it safe to turn down the ajax calls to a very short interval or is this implemented using something like websockets, etc.
If you’re curious, MessageBus is implemented using long polling (it does not support Websockets), which means the ‘live’ updating is done through requests which are held waiting on the server until something needs to update, at which point it responds with some data, and then initiates another ‘long’ request.
Is it necessary or even possible to stop subscribing if I switch to another page or for some reason don’t want my feed to update? That is without stoping any subscriptions in discovery.