Khalid
Khalid

Reputation: 1

JavaScript upload speed test any ideas or help?

am working on a internet speed test project for my company, i finished the download speed test part with the "onload" function, now am thinking in a way to test the upload speed like generating binary code on the customer side and send it to the server, so if you have any other idea or if you can help with the generating idea i'll be very thankful.

here is the code

> <script type="text/javascript">   
> beforeload = (new Date()).getTime();
> //i tried alot of things here but non is working
> $.post( "file",
> function(data){    afterload = (new
> Date()).getTime();    secondes =
> (afterload-beforeload)/1000;   
>     loadspeed = (513/secondes);   
> document.write("your download speed is
> " + Math.floor(loadspeed) + " kb per
> second");  }); </script> </body>
> </html>

thank you every one

Upvotes: 0

Views: 1307

Answers (2)

Emil Vikstr&#246;m
Emil Vikstr&#246;m

Reputation: 91892

You can use standard Ajax with POST to send a large blob of randomly generated data. On the server side, count the total number of bytes (including HTTP headers) and send this to the client in the Ajax response.

Make sure you have disabled gzip compression of the HTTP channel or you will get useless values :-)

Upvotes: 1

Martin Jespersen
Martin Jespersen

Reputation: 26183

You can use ajax in modern browsers. If you look at the XMLHttpsRequest object in newer browsers you will see that they have a property which is another XMLHttpsRequest that only describes the upload portion of the request.

The payload can be a large binary photo base64 encoded as part of the page you load's source code, that you then can post back to the server to do the upload test.

Upvotes: 1

Related Questions