Ajax response handling: innerHTML vs Sandboxed Iframe

JavaScript performance comparison

Test case created by Boye

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="content">
</div>
<script>
  function __getFrame() {
    var frame = document.getElementById("temp-frame");
    if (!frame) {
      // create frame
      frame = document.createElement("iframe");
      frame.setAttribute("id", "temp-frame");
      frame.setAttribute("name", "temp-frame");
      frame.setAttribute("seamless", "");
      frame.setAttribute("sandbox", "");
      frame.style.display = 'none';
      document.getElementById('content').appendChild(frame);
    }
    return frame.contentDocument;
  }
  
  function __createXhr(fn) {
    $.ajax({
      type: 'GET',
      url: '//jsperf.com/api',
      success: fn
    });
  }
</script>
    

Preparation code output

<div id="content"> </div>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
innerHTML approach
// async test
__createXhr(function(data) {
  document.getElementById('content').innerHTML = data;
  deferred.resolve();
});
pending…
Sandboxed Iframe approach
// async test
__createXhr(function(data) {
  var frame = __getFrame();
  frame.write(data);
  deferred.resolve();
});
pending…

Compare results of other browsers

Revisions

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

0 Comments