DEV Community

Discussion on: Caching AJAX requests with SessionStorage

Collapse
 
ssimontis profile image
Scott Simontis

A lot of developers forget that they have a nearly universal cache available to them...HTTP caching! If you use cache headers correctly, the browser does all of the work for you!

Client-side caching also forces you to consider a lot of security concerns. A user can easily access session state and modify it, compromising the integrity of saved responses and injecting untrusted data that is about to be parsed. SessionStorage is also synchronous, so the retrieval will be a blocking operation.

I would encourage you to explore service workers to handle your caching needs. IndexedDb gives you the power to store more expressive relational data and it is asynchronous to boot!

Collapse
 
bkimballbrian profile image
Brian Kimball

I believe you can use localforage library to asynchronously store data.

Collapse
 
uriel_hedz profile image
Uriel

Although I think that your concerns should be highlighted in the article so, what do you think if I add them as a warning, with credits to your comment?

Collapse
 
ssimontis profile image
Scott Simontis

Please feel free to do so! If you have any questions along the way feel free to ask.

Collapse
 
uriel_hedz profile image
Uriel • Edited

This is an alternative for simple cases in which introducing a service worker or an indexedDB database would be an overkill,