Deno: hope: XMLHttpRequest in deno

Created on 24 Apr 2019  路  4Comments  路  Source: denoland/deno

Most helpful comment

I really think XMLHttpRequest is a big ole can of worms. It is a really old API with a load of crap to try to make it compatible with the browsers. IMO we really have to draw the line of "browser compatibility" somewhere.

The best thing is that is someone desired, to use the built in Deno bindings to create a polyfill in std and bring it into core if it actually worked well.

All 4 comments

I believe XMLHttpRequest is needed for upload progress events.

Download progress can be measured with fetch already:

async function main() {
  let largeFileUrl = "http://download.inspire.net.nz/data/20MB.zip";
  let response = await fetch(largeFileUrl);
  let contentLength = parseInt(response.headers.get("Content-Length"));
  let readTotal = 0;
  let buffer = new Uint8Array(4096);
  let encoder = new TextEncoder();
  while (true) {
    let { nread, eof } = await response.body.read(buffer);
    readTotal += nread;
    let percent = ((readTotal / contentLength) * 100).toFixed(2);
    Deno.stdout.write(encoder.encode(`\r${percent}%`));
    if (eof) break;
  }
}

main();

I really think XMLHttpRequest is a big ole can of worms. It is a really old API with a load of crap to try to make it compatible with the browsers. IMO we really have to draw the line of "browser compatibility" somewhere.

The best thing is that is someone desired, to use the built in Deno bindings to create a polyfill in std and bring it into core if it actually worked well.

I agree with @kitsonk - it would be great if we didn't support XHR.

@MarkTiedemann I believe that "progress events" are available through fetch streaming?

Won鈥檛 implement

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sh7dm picture sh7dm  路  3Comments

ry picture ry  路  3Comments

ry picture ry  路  3Comments

JosephAkayesi picture JosephAkayesi  路  3Comments

metakeule picture metakeule  路  3Comments