Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
197
rated 0 times [  199] [ 2]  / answers: 1 / hits: 18125  / 14 Years ago, tue, december 28, 2010, 12:00:00

IS there any utility to measure bandwidth from my server to the client or any standard APIS.Need this for web application


More From » jquery

 Answers
7

Don't know of any utility or standard API, no, but you can do this by having several images of various sizes on your website, and then retrieving them bypassing cache and watching how long it takes for them to load. That information, along with the size of the image, gives you an indication of the speed between the two endpoints.



The reason for using multiple images is that you'll want to start small (say, 20k), but if the connection is fast that will give you a very inaccurate number; so based on how quickly that image loaded, you'll want to select another image of an appropriate size to try to get a better idea of the actual bandwidth (as opposed to the latency setting up the connection and such).



You can do this just with straight JavaScript, by adding img tags off-page with a unique query string to bypass caching; but as you've tagged your question jQuery, you may find it more convenient to use the .ajax function (with its cache: false setting) instead.



The speed number you come up with is only an indication, since other things could be going on that mess up your timing (video streaming in another tab — or on another computer hooked to the same internet connection, even other things slowing up the execution of your JavaScript, like a JS-heavy animation on the page), but it should be good enough to give you an idea what you're working with.


[#94463] Sunday, December 26, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
joaquin

Total Points: 150
Total Questions: 103
Total Answers: 113

Location: Saint Helena
Member since Tue, Nov 3, 2020
4 Years ago
;