DEV Community

Discussion on: Detect Internet Connection Status In Browser

Collapse
 
jwhenry3 profile image
Justin Henry • Edited

I like the simplicity and the fact you list the edge cases that may cause inaccuracy.

I wonder what the consensus is on polling a same-host endpoint as a ping (by updating the response with the current timestamp) to check the connection can at least reach the remote destination

With WebSocket, this becomes slightly less important due to the connect and disconnect events firing as expected so long as reconnect is configured.

Collapse
 
bibekkakati profile image
Bibek

Polling is a good way, but to use it as an alternative to the listeners we will have to poll very frequently.
I prefer to use the listeners as those side cases are not so impacting. After a false-positive result, if we send a valid request and it fails, we will get to know about the false-positive status. At last, it depends on the application and it's working.