Search code examples
javascriptperformanceapicachingoffline-caching

Client-side caching (with JavaScript)


I have a API that I'm querying via JS on a client side and then displaying result on a page (again via JS).

I have a limit of 5 queries per second. In real life i can send maximum of 11 API calls in one loop.

What i need:

  1. I need somehow to bypass 11 queries limit, because usually i need to make about 50 calls in one loop.

  2. I need to make sure that I'm not sending the same API requests on every page refresh.

The obvious solution is caching. To comply with speed requirements, ideally i would like to cache data on the client's side.

The question:

How? I don't think that cookies is a good solution because of the 4KB size limit. I heard about Google-gears (that they use for Offline-Gmail.) but recent search result showed that it doesn't exists anymore.


Solution

  • You can use localstorage but only if you need the cache to remain between refreshes of the browser. If you don't then you can use memory like hold it in array or result.