Skip to content
Advertisement

JS: XHR loads files (>50MB) immediatly

I’m making a internet speedtest app with Node.js. Everything works fine expect the download test. I normally download at 8Mbits/s but when I try XHR requesting a text file / image (about 256 MByte) at /public/chunk/somefile.txt for example, it downloads it within 1 second which is impossible. Then I checked the onprogress log:

Image

How comes that it loads the image so fast? I mean it isnt cached or anything. Anyways here’s the code:

const fileUrl= "/public/chunk/d.jpg";

xhr = new XMLHttpRequest();
xhr.onprogress = (e) => console.log(e, e.loaded - e.total);
xhr.onloadend = () => { console.log("end")};
xhr.open("GET", fileUrl, true);
xhr.setRequestHeader('Cache-Control','no-cache');
xhr.send();

BUT: Here’s the thing, if I put in a image url for example: https://upload.wikimedia.org/wikipedia/commons/f/ff/Pizigani_1367_Chart_10MB.jpg . It works! Why?

Please let me know why it doesn’t work, I’ve been trying around since 5 hours now. Thanks in advance.

Advertisement

Answer

If you run the web server in on a local machine, the transfer rate is not limited to the rate your ISP provides in your area to access the WAN.

If you test it with another device in the same local network, 50MB might be nothing and will be transfered at half of a second or less.

  • A gigabit LAN connection can transfers up to 125MB/s
  • Wireless connections with 866MBit transfer up to 108MB/s

Depending on the hardware and network setup you can transfer larger files within seconds which may give you unexpected results on speedtests. You can throttle the download speed on the client side using the dev tools of the browser or plugins as mentioned in this answer.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement