473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Download speed test

Hi I am trying to measure download speed from server with ajax call and xmlwebrequest, I download a 1 mb file and check the total time. However it shows just response time from server and doesn't wait until all file loaded for 2 methods I showed below. What am I doing wrong? Any other ways are welcome. Thanks...

First method I am tring is

Expand|Select|Wrap|Line Numbers
  1. var start = new Date();
  2. $.ajax ({
  3. url: 'https://www.example.com/perftest/dummyFile1024',
  4. cache: false,  
  5. success : function()
  6. {
  7.  var total=(new Date() - start)
  8.  alert(total)    
  9. },
  10.  error : function(jqxhr, status, ex) {
  11. })
Second method is

Expand|Select|Wrap|Line Numbers
  1. var start = new Date();
  2.  (function rec() { var start = new Date().getTime();
  3.  var xmlHttp = new XMLHttpRequest();
  4.  xmlHttp.open('GET', "https://www.example.com/perftest/dummyFile1024",true);   
  5.  xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  6.  xmlHttp.onreadystatechange = function () {
  7.  if (xmlHttp.readyState == 4) {
  8.    var total=(new Date() - start)            
  9.   alert(total)          
  10. };
  11.  }; xmlHttp.send(null);
  12. })();
Jan 14 '13 #1
8 4328
Anas Mosaad
185 128KB
You may try using an image. An image has a property onload that should help you on this. For example:
Expand|Select|Wrap|Line Numbers
  1. var img = document.getElementById('myimg');
  2.  
  3.     img.onload = function () {
  4.         alert ("The image has been loaded!");        
  5.     };
  6.  
Please let us know the results you got, hope it can help.
Jan 14 '13 #2
I want to measure download speed not for one server. There will be 3 regions that client can measure download speed from these 3 servers located in these regions. How can I use this image onload property for different servers?
Jan 14 '13 #3
Anas Mosaad
185 128KB
I was trying to answer the question about knowing how much does it take to load the object. If your object is a files, the above method is perfect for you. If you have another method, I don;t know this can be implemented.
Jan 14 '13 #4
Sorry I am not good for web development and my question with your method how can I load pictures from different servers. for example your code loads 'myimg' which is located at same place with the webpage.
Expand|Select|Wrap|Line Numbers
  1. var img = document.getElementById('myimg');
I use at my methods different URL's to call the files in different servers. Could you give advice how to do that with images. Thanks for your answer...
Jan 14 '13 #5
Anas Mosaad
185 128KB
For example you'll create a div with id container to hold the images. From JavaScript you can add images ass follows:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function xLoad() {
  3.     alert('Image was loaded ...');
  4. }
  5.  
  6. document.getElementById('container').innerHTML = '<img src="http://solutions.devx.com/imagesvr_ce/1779/topad.png" onload="xLoad()" />'
  7. </script>
  8.  
You may style the container div to be hidden if you don't want it to be visible for the user.
Jan 14 '13 #6
That is perfect. I will give a try and let you know about result. Thank you very much...
Jan 14 '13 #7
Anas Mosaad
185 128KB
I appreciate if you can share with us the solution you adopted.
Jan 19 '13 #8
Hi Anas, I tried your solution to measure bandwidth test, It works perfect. Thank you.
Moreover I found something with my code I mentioned above, at the ajax call when I set async:false, anymore it waits to download whole file what was my problem, so I am able to measure download speed with this method as well. However internet explorer and firefox is still the same. chrome, safari works well now. Do you have any idea why it is happening?
Thanks again...

Edit: I have asked this at another question. http://bytes.com/topic/javascript/an...se#post3739059
Jan 21 '13 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: bart | last post by:
i want to calculate a user download speed. what would be the best way, let a java script calculate it?, or let php do it? i was thinking of using an image as testfile. with php i could send the...
4
by: D. Alvarado | last post by:
Hello, I would like to design a page that measures the user's download connection. Does anyone have an example link or script that might aid me in this task? Thanks, - Dave
12
by: chipgraphics | last post by:
:confused::confused: I have been on the quest to find a php script that can serve files for downloads and limit the speed at which the file is transfered to the user. I want a faster download...
3
by: Crouchie1998 | last post by:
How do I work out the download speed in KB/Sec & how many hours/mins & seconds left? Thanks in advance for any help
2
by: David R. | last post by:
Is there a way to measure and report the up/download speed between the server and the client browser using ASP.NET 2.0 C#?
1
by: bigpoppa | last post by:
Hey, I need a script that will limit download speed and I want it integrated into the script I am using below. The script below forces downloads and hides url paths and logs stastics of downloads and...
5
by: Pitaridis Aristotelis | last post by:
I have a large file which has to be downloaded from a user using the Internet Explorer. The problem is that when someone downloads this file, the server slows down and the other users can not see...
2
by: =?Utf-8?B?Z3JlYXRiYXJyaWVyODY=?= | last post by:
Hi, I know there isn't a specific event property for the download speed, but can anyone tell me how to find it? I'm not sure how to write the code. Thanks, Jason
2
dlite922
by: dlite922 | last post by:
I have an intranet LAMP server and I use PHP to upload files. It is of course faster to download the same file than to upload it. I understand ISPs throttle their network for download speed, than...
4
by: nestle | last post by:
I have DSL with a download speed of 32MB/s and an upload speed of 8MB/s(according to my ISP), and I am using a router. My upload speed is always between 8MB/s and 9MB/s(which is above the max upload...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.