Closed ayushn21 closed 2 years ago
Another option I found is the message_bus plugin: https://github.com/jeremyevans/roda-message_bus example app: https://github.com/jeremyevans/lila_shell
It uses the MessageBus gem from the Discourse folks: https://github.com/discourse/message_bus
Currently, live reloading works by polling an endpoint that checks for changes and refreshes the page:
https://github.com/bridgetownrb/bridgetown/blob/90a73bb5c74f005dddd90e263424d9872fde450d/bridgetown-core/lib/bridgetown-core/utils.rb#L402 https://github.com/bridgetownrb/bridgetown/blob/90a73bb5c74f005dddd90e263424d9872fde450d/bridgetown-core/lib/bridgetown-core/rack/routes.rb#L56
This works well but I think there's scope for improvement here.
The first approach worth investigating is Server Sent Events. We should be able to set up the
live_reload
endpoint to stream responses using the Roda Streaming Plugin. On the client side we can useEventSource
to create the connection, listen for the events and trigger a refresh. There's still a lot of unknowns like how to watch the files and send responses; or whether this approach will even work.If the above doesn't work, it's also worth investigating a WebSockets based approach I reckon.