Link to home
Start Free TrialLog in
Avatar of ranirajesh
ranirajesh

asked on

Redirect users according to their bandwidth using Javascript

Hi

Depending on the users bandwith I have to redirect the users to different asp pages
Is there a way to find if they are using high / low bandwith and redirect accordingly in Javascript ?

Thanks

Avatar of ethoths
ethoths

There is no precise way to do it but you could try this....

1) Create a page with some javascript i the head that gets the current time.
2) As the last line in the body get the time again. The difference between the two will be a measure of how long the page took to load (and hence the bandwith).
3) Depending on the time determined in 2 redirect to the appropriate page.

This will require a little calibration to get right and the page that you use to do this will have to have some amount of content to make it take some time to load but it should work.

(Another way would be to do the same thing in AJAX. Since this is asynchronous your users should not notice any delay.
@ethoths - I don't believe your theory will work. Since Javascript is only processed once the code is already in the browser - calculating the time between to 'head' and 'footer' times is more a measure on how fast the client machine runs the script.

AJAX is a closer measure but again there are issues with server traffic etc. that would affect the response time and not sufficiently give you an accurate time. You could try it by taking the current time in JavaScript - place an AJAX call to an .asp page, take the time when the response is recieved - subtract the difference of the two times and subtract the processing time of the .ASP page and you will get a (somewhat inaccurate) measure of bandwith.

Yes you are right, the code will run as soon as it is in the browser. The code in the head will run just after the page starts loading and the footer code when it is loaded. It's not really measuring the time it takes the page to load, rather it's taking a measure of the time elapsed between the head code loading and the footer code loading. This is somewhat related to the time that the page takes to download.

My understanding was that the requirement was to determine whether the user has a low bandwidth connection (56k Modem) or a high bandwidth 2Mb ADSL. If this is the case then there is a factor of 40 between the them. In this case accuracy is not really required. If the page loads in less than 1 second then it's ADSL, if it takes more than say 20 then it's not. A bit of imperical calibration will yeild reliable results.

I agree that the AJAX approach will yeild even better results but it might be a little overkill for a simple "go/no-go gauge".
ASKER CERTIFIED SOLUTION
Avatar of flipz
flipz
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ranirajesh

ASKER

Thanks to both of you ... My mistake for not responding earlier ...  for the time being I have left the choice to the user , but in future I would definitely like to try out using AJAX