Solved

Redirect users according to their bandwidth using Javascript

Posted on 2007-04-03
6
311 Views
Last Modified: 2013-11-25
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

0
Comment
Question by:ranirajesh
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:ethoths
Comment Utility
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.
0
 
LVL 11

Expert Comment

by:flipz
Comment Utility
@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.

0
 
LVL 11

Expert Comment

by:ethoths
Comment Utility
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".
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Accepted Solution

by:
flipz earned 250 total points
Comment Utility
ethoths - as I understand it - the actual JS code does not actually run until the page is fully loaded. Even if you put a timestamp in the head of the page - the JS call to get that time will not fire until the entire HTML is loaded into the browser. This means that any JS code running would have nothing to do with bandwith.

I agree that there is a considerable difference between dial-up and ADSL so some innacuracies are acceptable but what if a user on ADSL runs the page but the server is too busy to respond and takes 20 seconds to run? Then the client code would assume that the connection is dial-up.

In any case - ranirajesh - you're probably just better off the let the user choose their own connection speed.
0
 
LVL 11

Assisted Solution

by:ethoths
ethoths earned 250 total points
Comment Utility
Yes flipz: you are correct about the running of the JS and my first suggestion would not run. My suggestion about AJAX looks like the best way.

Incidentally, the fact that a slow server or connection could result in tha inaccurate selection of page is a good thing. It does not really matter why the page is slow to load. If it is slow for any reason then the leaner version should be used.

Letting users choose has several disadvantages...

1) Some users won't know.
2) Some will choose the wrong answer
3) Some will be scared off by such a technical question.
4) It cannot dynamically auto configure
5) If the choice is perisited as a preference and the user then upgrades, they will not be getting the best experience.
0
 

Author Comment

by:ranirajesh
Comment Utility
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
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Read about why website design really matters in today's demanding market.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now