SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2002
    Location
    Vermont, USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting Internet Connection

    This may be a stupid question, but I've never seen it touched on before: Is it possible (via a JS sniffer or some other code) to determine a visitor's internet connection speed and then deliver the appropriate content based on the result? ie - people w/ high speed connections get a high-bandwidth Flash version of a page; those w/ dial-up get the flat, HTML version. I'd rather not have a splash page at the beginning of my site that asks the user to choose between which version they want to view. Is this possible?

  2. #2
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't mind that the solution will be very unreliable and dependant on what the user is doing in other browser windows....
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html>
    <head>
    <script type="text/javascript">
    var img = new Image();
    var fastEnough, loaded = false;
    setTimeout("fastEnough = loaded", 1040);
    img.onload = function() { loaded = true; };
    /* URL to an image of appropiate size, for example
    16K if the connection speed must be at least 16KB/s */
    img.src = "http://example.com/foo.jpg" + "?" + Math.random();
    setTimeout("speedtest()", 1100);
    
    function speedtest() {
    	location.href = fastEnough ? "flashpage.html" : "noflashjunk.html";
    }
    </script>
    <title>Wait...</title>
    <body>
    <p>Checking connection speed, <a href="noflashjunk.html">click
    here if you don't get redirected...</a></p>
    </body>
    </html>

  3. #3
    SitePoint Member
    Join Date
    Mar 2002
    Location
    Vermont, USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. That's an interesting approach. I'm going to try it out and run some tests to see what happens. I'm wondering if there is a different approach, which allows you to avoid re-direction and simply renders the same page w/ either the flash content or html to replace it instead (via the document.write() method, possibly?)

  4. #4
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, you could move the whole script to the body section, then use document.write inside the speedtest function.

  5. #5
    SitePoint Member
    Join Date
    Mar 2002
    Location
    Vermont, USA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Saturn
    Sure, you could move the whole script to the body section, then use document.write inside the speedtest function.
    I feel like a donkey asking you this, but is there any way you could write this out in your example. My JS skills are not the best. Thanks in advance.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •