I want to test how my statically rendered site looks like before a WebSocket connection is established. Is there an easy way to disable the “hydration” part of the LiveView life-cycle? That is, prevent LiveView from establishing a WebSocket connection (or at least delay it by a lot?).
I tried the following so far:
- Add
window.WebSocket = undefined
before the
let liveSocket = new LiveSocket(...)
call inapp.js
- This prevents LiveView from using WebSockets, but causes it to fall back to longpolling. If longpolling isn’t implemented, the site refreshes every second and retries the longpolling. - Add a timeout when the socket is connected:
def handle_params(_params, _url, socket) do
if connected?(socket), do: :timer.sleep(10_000)
{:noreply, socket}
end
This actually works quite well, but I wondered whether there’s a setting to disable the WebSocket connection entirely?