deprecation XMLHttpRequest [duplicate]

1

I'd like to know how to sort my code XMLHttpRequest , it's giving me this [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. message when I try to get the size of a img in bytes . NOTE: I already tried to change this: request.open("HEAD", imgURL, false); by: request.open("HEAD", imgURL, true); , but the return size of img is 0 when I do this. below is the complete javascript function

function getImageSizeInBytes(imgURL) {
      var request = new XMLHttpRequest();
      request.open("HEAD", imgURL, false);
      request.send(null);
      var headerText = request.getAllResponseHeaders();
      var re = /Content\-Length\s*:\s*(\d+)/i;
      re.exec(headerText);
      return parseInt(RegExp.$1);
  }

How do I resolve this message from deprecation that is returning?

    
asked by anonymous 29.12.2018 / 16:33

0 answers