The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

OK, I've given away a lot of advice and scripts around here. Can anybody return the favor?!

I need a script that detects the user's download speed. I've seen of couple of examples on the web, but I'm stumped on a particular part.

Basically, the page that detects the speed uses JavaScript to start a timer, then there is some data to load in the middle, and another JavaScript to stop the timer. Then a few calculations are done on the start and end time, taking into consideration the size of the data, and you end up with a rough idea of the kilobytes per second the user is capable of.

The hard part: The data that loads in the middle is compressed binary, between comment tags. How do I get the compressed binary into my page? I've tried copying what I've seen, but it either prints out to the page (even though it's in comment tags), or it freaks out my editor to the point where I can't even work with the page anymore.

Confused? If not and you have any insight into this, please share! Thanks.

There's a glitch in that one however, since you can't reload the page and get a result. I've solved this in my example by always appending a random number to the end of the URL of my script, and a random number on the end of the gif that I load, to prevent caching.

The other was on CNet, but I don't have the link to that one at the moment.

Creole:

Thanks for the link, I'll check that one out and see what kind of results it gives.

In the meantime, I just used a gif, and timed it's download to get a rough idea of the user's speed. It isn't completely accurate, but it gives a good ballpark estimate, since I'm only wanting to determine if the user has a 56K modem, or a DSL or faster connection. Most of the examples I saw on the web used compressed binary code to time the download, and they indicated it would be more accurate since their was little chance of the data being further compressed in transit.

Thanks for the link scrubz. I don't have time to look into it much at the moment, but one comment I have (and I know this is being a bit picky and you didn't ask for it ) is that with a random number you could potentially hit the same one twice. Probably not too important for this application, but for future reference another option that gets rid of this potential problem is to use a time stamp instead of the random number.

I'm headed in a million different directions this week, so this little task is on hold for now. Thanks for the info JWatt - good point about the random number. Although there's a small chance of a duplicate random number (between 1-100000), I see your point. The timestamp is a good workaround for this.