T.Im
T.Im

Reputation: 159

Is it possible to save large amounts of data on the client side with node.js?

I was wondering if it would be possible to save large amounts of data on the client side with node.js. The data contain some images or videos. On the first page visit all the data should be stored in browser cache, so that if there is no internet connection it would not have effect on the displayed content .

Is there a way to do this ?

Thanks for your help :D

Upvotes: 0

Views: 1734

Answers (1)

O. Jones
O. Jones

Reputation: 108696

You can use the Web Storage API from your client-side (browser-side) Javascript.

If your application stores a megabyte or so, it should work fine. It has limits on size that vary by browser. But, beware, treat the data in Web Storage as ephemeral, that is like a cache rather than permanent storage. (You could seriously annoy your users if you rely on local storage to hold hours of their work.)

You can't really get a node.js program itself to store this information, because those programs run on servers, not in browsers. But you can write your browser-side Javascript code to get data from node.js and then store it.

From browser Javascript you can say stuff like

window.localStorage.setItem ('itemName', value)

and

var retrievedValue = window.localStorage['itemName')

window.localStorage items survive browser exits and restarts. window.sessionStorage items last as long as the browser session continues.

Upvotes: 1

Related Questions