Over a million developers have joined DZone.

How Much Does Caching Matter in JS?

· Performance Zone

Download Forrester’s “Vendor Landscape, Application Performance Management” report that examines the evolving role of APM as a key driver of customer satisfaction and business success, brought to you in partnership with BMC.

Caching plays a very important role on both the client and server side. I tried to do a little test with benchmark.js, and caching proved to increase performance remarkably. In fact, the cache-less query was 98% slower than the cached query! Cache has its limitations with live objects, but it's worth a timely cache update in that case.

Below is the simple test code and some numbers from the test:

<div id="docs">
  Benchmark.prototype.setup = function() {
    var divs = document.querySelectorAll('div#docs')
    var cache = {get: {'divs': divs}};

Test code:



document.querSelectorAll('div#docs').length => 135,809 (ops) 98% slower.

cache cache.get.divs.length => 8,212,190 (ops) 0.99% faster.

Do let me know if you find a better way of speeding things up!

See Forrester’s Report, “Vendor Landscape, Application Performance Management” to identify the right vendor to help IT deliver better service at a lower cost, brought to you in partnership with BMC.


Published at DZone with permission of Hemanth HM, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}