Better reconnection handling in client JS