How to detect connection speed?

Is there any way you can detect the users connection speed using javascript? or do you have to do it on the server side? if so, how?