Caching page data

JavaScript performance comparison

Test case created by Phillip Gourley


Spike for storing page meta data inside an object to limit requests to the DOM to improve performance.

Preparation code

<script src="">
<div class="basket">
Benchmark.prototype.setup = function() {
    var siteObj = {
      page: {
        type: 'basket'
    $body = $('body');

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
DOM request to retrieve data
// Not used cache selector to replicate bad practice.
if ($('body').hasClass('basket')) {
  return true;
Cached value to retrieve data
if ( === 'basket') {
  return true;
DOM request to retrieve data (cached)
if ($body.hasClass('basket')) {
  return true;

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment