0

I'm creating a web, to calculate how much data usage is required if a specific url is entered in a form. I know to how to create a form, but I couldn't find any resources to look for internet required a given url. Is there any API for it, please help me out!

I tried refering to website like

  1. How to calculate mobile and wifi data usage of each application in android? - which is android specific
  2. How to calculate bandwidth usage for Javascript? - didn't get what I expected.

What I expect is, to get how much mega bytes of data is required to load this url. Is it possible to calculate?

1 Answers1

0

Use fetch api and blob method to get size.
Tested in nodejs.
In browser, test with same origin url otherwise CORS error will throw.

fetch("https://stackoverflow.com/")
    .then((response) => response.ok && response.blob())
    .then((data) => {
        console.log(data.size) //in byte
        console.log(data.size *  1000) //in kilo byte
    })
    .catch((err) => console.error(err));
Anil kumar
  • 1,216
  • 4
  • 12