The most suggested way to get the bandwidth (both upload and download) is to download/upload a file of known size, take the difference of the start time and end time, then divide the size by the time it took to download/upload it.
The most suggested way is also the easiest way since:
- you know the size of the file
- you can get the time it takes to download
- and you have control of the time when it starts and finishes
Normally you can. But the problem with gauging the speed using the resources loaded on the current page is that you need to hook into every resource, which includes (but not limited to):
- images
- scripts
- stylesheets
- frames
- XHR (AJAX)
- sockets
- the page itself
- and other stuff I missed.
Pages load resources in a combination of sequential and parallel requests which start and end at varying points in time. Some may even delay loading using loader scripts, which at the time you try to check, might not have responded yet.
Also, if you use this script, this script must load way before everything to hook into everything on the page. Another problem here is that not all resources have a reliable onload
event, especially the link
element.
I suggest you stick to the easy method.