Ant
09-11-2004, 21:06
Is it possible to recognise the connection speed of a website visitor and, using an if/then routine, load customised pages? What code would I use?
|
View Full Version : Website Advice (html, cgi, java etc) Ant 09-11-2004, 21:06 Is it possible to recognise the connection speed of a website visitor and, using an if/then routine, load customised pages? What code would I use? JoeP 09-11-2004, 21:44 Interesting idea.... I've never tried this and what I usually do when a client wants this sort of functionality is suggest they have a link to the low bandwidth version of the site form the main index page. You MIGHT be able to put something together that times a download form the site, but I'd have to think about it. Not saying it's impossile, but never seen it done. Joe Cyclone 09-11-2004, 21:48 could you do something involving a cookie and an autoredirect to time how long it takes between them hitting page 1 and making a request for page 2? Not all that robust though, afterall, their connection speed isn't the only thing that will affect the throughput from site to browser. Most reliable way is to give them the option of going to whichever is more appropriate. Martin_s 09-11-2004, 23:55 Not heard of anything that could handle this... There'd be a whole slew of variables en route such as caches, proxys, etc... that would affect the speed so I'd have to say the old human interaction route has to be the best.. Ant 09-11-2004, 23:57 Ok, thanks dudes. sccsux 18-11-2004, 16:59 You can get a decent aproximation of connection speeds through Java. I have a simple script that measures the speed of a connection. <script> var loaded=new Array(); var images=new Array(); var count=0; var loadedcount=0; var img; var d1, d2; var speed; //Image URL var imgsample="testingimage.jpg"; //Image size in bytes var imgsize=16193; function RoundNumber(num, points){ //This function rounds a number var strnumber=new String(num); if(points<1) return num; var decimal=strnumber.indexOf("."); if(decimal<0) return num; return new Number(strnumber.substring(0, decimal+points+1)); } function TestSpeed(){ //Set the Image Object img=new Image(); document.speedchecker.thespeed.value="Checking Speed..."; //Set a new date object with the current time d1=new Date(); //Download the image in the variable "imgsample" img.src=imgsample; //Call the function that checks when the image downloading finishes CheckImageDownload(); } function CheckImageDownload(){ //If image download is completed if(img.complete){ //Set a new date object with the current time d2=new Date(); //Calculate the difference in milliseconds between d1 and d2 var diff=d2.getTime()-d1.getTime(); //Convert the milliseconds to seconds and round the number to 2 decimal points if(diff!=0) seconddiff=RoundNumber((diff/1000), 2); else seconddiff=4; //Get the internet connection speed by dividing the //image size in KB by the download time in seconds speed=RoundNumber((imgsize/1024)/seconddiff, 2); //Show Internet Connection Speed document.speedchecker.thespeed.value="Connection Speed: " + speed + " KB/sec"; } //If image is not downloaded yet then check for it every 100 milliseconds else setTimeout("CheckImageDownload();", 100); } </script> Stick the above between the HEAD tags on a web pag, with the following in the BODY of the page: <form name="speedchecker"> <p><input type="button" value="Check Speed" name="B3" onclick="TestSpeed();" style="border: 1px #000000 solid; font-family:Arial; font-size:13px; width:300px;"><br> <input type="text" name="thespeed" size="46" style="border: 1px #000000 solid; font-family:Arial; font-size:13px; width:300px;"></p> </form> When a visitor clicks on the displayed form button, thtier connection speed is displayed. It doesn't redirect or anything, but it shouldn't be too difficult to customise it to do so..... JoeP 18-11-2004, 19:29 Looks good! However, at the risk of getting the Pedantic ******* award (again!!) surely it's measuring the throughput of the end-to-end connection rather than the connection speed? Of course, this is the speed the user is interested in but be very careful about publicising the speed estimated because it's always going to be lower than the baud rate they think they're paying for! Joe sccsux 18-11-2004, 20:25 Originally posted by JoePritchard Of course, this is the speed the user is interested in but be very careful about publicising the speed estimated because it's always going to be lower than the baud rate they think they're paying for! Joe Yeah, I know. However, this method would work in Ant's case as you could then serve up different pages based on the approximation returned by the script ie. if the speed returned < (say) 10K/ps = dial-up/crap dsl/cable content, anything above = BB/DSL content. JoeP 19-11-2004, 10:45 Yep, It's a nice fix! Thanks! Joe Ant 25-11-2004, 00:57 Thanks for that, sccsux. Much appreciated ! |