I want to detect the user's connection speed to offer an improved website experience. As an example, use 20 records per page pagination, but allow the detection script to change that to higher or lower (as well as other things).

How is the best way to do this, and can someone point me in the right direction?

I also want to detect connection speed when displaying HTML 5 video (which I haven't looked at yet). Is it best to use the same script for everything, or use a HTML 5 player with that feature in it?