localStorage versus browser cache (v4)

Revision 4 of this benchmark created by Anton Ignatov on


Description

Is it quicker to retrieve a javascript file from localStorage than it is to let the browser fetch a cached copy from its own cache?

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
// A random URL from a CORS enabled data source
var url = "http://aignatov.ru-br.4game.com.dev/test.js";

localStorage.setItem('file', 'if (resolveHandler2) { resolveHandler2(); }');
</script>

Teardown


    var script = document.getElementById('lc');
    
    if (script && script.parentNode) {
        script.parentNode.removeChild(script);
    }
    
    script = document.getElementById('bc');
    
    if (script && script.parentNode) {
        script.parentNode.removeChild(script);
    }
  

Test runner

Ready to run.

Testing in
TestOps/sec
localStorage
// async test
resolveHandler2 = function() {
    setTimeout(function() {
        deferred.resolve();
    }, 1);
}
script = document.createElement('script');
script.id = 'lc';
script.innerHTML = localStorage.getItem('file');
document.getElementsByTagName('head')[0].appendChild(script);
ready
Browser cache
// async test
resolveHandler = function() {
    setTimeout(function() {
        deferred.resolve();
    }, 1);
}
script = document.createElement('script');
script.id = 'bc';
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
ready

Revisions

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