0

I have an application where the user downloads images. I want it so the user and scroll through their downloaded images without having to call the api again.

When the user closes the webpage I want all these cleared so there is no need for persistent storage.

The images are around 1mb in size so I am wondering should I store them in a array on the component page and set a size limit so that the browser will not crash if it gets too large?

How large is too large in terms of file size for most browsers?

Jacob
  • 37
  • 1
  • 1
  • 4

1 Answers1

0

You just never know how much memory your clients have available, so trying to guess how many large images you can keep in memory is somewhat like playing with a loaded gun.

If you can limit this to a small handful of images, then you're probably ok, but if the number of images to be stored is large, or limited only by user actions, I'd store them in localStorage. You can clear localStorage when your application unloads.

For one approach for storing images in local storage, take a look at this SO answer.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • Will there be a issue if I store too many there, or will they get warned that it is filling up? Also would sessionStorage be better as it clears when they close the app right? – Jacob Apr 09 '20 at 13:29
  • Res: SessionStorage: Maybe. LocalStorage gives you a single storage location based on the document origin, while SessionStorage gives you a storage location per tab or window, regardless of the document origin. Unless you can deal with that, you are better off using LocalStorage, and deleting it when you app gets destroyed (e.g. onDestroy() lifecycle method of your app component). As far as filling up...I didn't realize, the limit on Chrome is 5Mb, and you'll get an exception when you try to exceed that. So it looks like your limit for 1Mb images will be approximately 5. – GreyBeardedGeek Apr 09 '20 at 19:58
  • Alright I will just store them in an array on the page and set a limit of 20 images or so. I can start removing from the front if they exceed that. If their computer can't handle 20 images I think they other things to worry about. – Jacob Apr 10 '20 at 19:40