I'm fairly inexperienced in frontend engineering, so I apologize if this comes off as naive or too broad.
My app fetches 4k JSON objects via AJAX. To prevent repeated HTTP requests, the returned JSON is cached in an object within the global window scope. Are there any best practices regarding this sort of thing?
I realize that a reasonable limit on the size of the cache will depend on the the browser, the OS, hardware, and other factors. I'm on the look out for degraded UI responsiveness.
Are there any good rules of thumb, though?
The size of this memory ranges from 1 MB to 8MB.
Memory caches smaller than 1 MB are nonfunctional, and the performance of caches smaller than 5 MB is usually unsatisfactory. Suitable upper limits are similar to those for disk caches but are probably determined more by the demands on memory from other sources on the machine (number of users and processes).
This begs the question of what happens if the cache memory is already full. The answer is that some of the contents of the cache memory has to be “evicted” to make room for the new information that needs to be written there.
Caches are generally small stores of temporary memory. If they get too large, they can cause performance to degrade. They also can consume memory that other applications might need, negatively impacting application performance.
This strongly depends on your task and large percent of users you would like to have.
If you have nice 3D game, then even 500MB would be ok (but not all for JSON cache)
Modern browsers require 50-100MB of memory from the start. Therefore 50MB for all your javascript objects should be ok in most cases and I suppose 50MB is large enough for any simple(twitter)/average(gmail) web app.
Also, RAM costs 5-7$ per GB now.
Keep in mind, that, 4k of stringified JSON will turn into 10-50kb in objects and even in string form will take almost 8k (If you use utf-8 for http transfer) since js engines uses UTF-16 for internal string representation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With