开发者

JavaScript upload speed test any ideas or help?

开发者 https://www.devze.com 2023-02-05 10:43 出处:网络
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 generat开发者_J

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 generat开发者_JS百科ing 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


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.


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 :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消