Is there any method for handling low memory conditions at runtime in JavaScript?

If your web application should run on embedded or low-level devices, is there a means in JavaScript to manage low memory conditions at runtime so that you can use as much memory as possible to cache data, but be able to reliably clear such caches if necessary?

An example would be an application in which there is a local storage of logical data, for example, a map of the map of the data object that it uses, and not repeat new requests on the server. I would like to be able to populate this cache with a watermark, which can be determined at runtime in my JavaScript application.

I have not found anything so far, but I hope that I just missed something.

+4
source share
2 answers

No. The browser does not provide memory usage statistics for JavaScript.

If you are trying to implement caching, you are probably better off using the browser cache (for example, using the Expires: headers for AJAX responses) rather than trying to implement your own cache in JS.

+3
source

You can use localstorage or IndexDB to cache the results for you (on most devices / browsers the actual size limits are pretty well known), so you don't need to know the memory consumption in javascript.

If you use phonegap (http://www.phonegap.com), you can easily receive memory warnings in your own code and send them to javascript. I did this in several situations where it was possible to clear the DOM and recount it later if necessary.

+1
source

Source: https://habr.com/ru/post/1387257/


All Articles