What is the best way (i.e. simplest implementation and most transparent to the end user) to calculate ping times between a website visitor and a set of IP’s? I know that SpeedTest.net does this in their speed test calculations, though my solution does not need to be visible to the user. It should simply calculate ping times and then select the lowest ping.
To be clear, I want the end user to ping the IP’s. I do not want the remote servers to attempt to ping the end user’s connection because their connection may not allow te packets through.
Example of ping time given by SpeedTest.net when you run a test:

Open a connection to the server with a WebSocket, time how long it takes. It’s not exactly a ping, but it’s probably as close as you can get with javascript.
There’s an example of this method on this page.