Abusing jQuery $(document).ready

Benchmark created by Ross Kaffenberger on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  function listen() {
    $('#doesnt-exist').click(function() {
      return false;
    });
  }
  
  function listenTwo() {
    $('#doesnt-exist-2').click(function() {
      return false;
    });
  }
  
  function listenThree() {
    $('#doesnt-exist-3').click(function() {
      return false;
    });
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Single $(document).ready
$(function() {
  listen();
  listenTwo();
  listenThree();
});
ready
Multiple $(document).ready
$(listen);
$(listenTwo);
$(listenThree);
ready
Multiple nested $(document).ready
$(function() {
  listen();
});
$(function() {
  listenTwo();
});
$(function() {
  listenThree();
});
ready

Revisions

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

  • Revision 1: published by Ross Kaffenberger on