xhr image embedding

Benchmark created by Broofa on


Preparation HTML

<img id="dst" />

Setup

xhr = new XMLHttpRequest();
    img = document.getElementById('dst');
    urlBase = 'https://2.gravatar.com/avatar/b072fc2897196b3bafcd337bc9c91e2d?s=140?foo=';

Test runner

Ready to run.

Testing in
TestOps/sec
set to remote url
// async test
var url = urlBase + Math.random();
xhr.open('GET', url);
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
    img.src = url;
    deferred.resolve();
  }
}
xhr.send();
ready
set to data url
// async test
var url = urlBase + Math.random();
xhr.open('GET', url);
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
    img.src = 'data:image/jpeg;base64,' + btoa(unescape(encodeURIComponent(xhr.response)));
   deferred.resolve();
  }
}
xhr.send();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Broofa on