简体   繁体   中英

Can I safely store base64 images in local storage?

I would like to save an image to reuse it on several pages. The simplest way for me would be to use local storage.

Now, I'm wondering if it is a safe option. I'm not sure about the size of the generated image, so I'm afraid that it could sometimes exceed the limit of the local storage capacity.

If it can help, here are the characteristics of a typical image:

  • 980x653 PNG
  • When saved, it weighs ~400ko
  • base64 is ~33k chars (but I guess it can easily double)

Checkout this question:

How to store and retrieve image to localStorage?

It should provide you with more insight to what the best way to achieve this is. If you can guarentee that the image won't be greater than 5mb then go ahead! You could always do some validation to check whether it's too large. You could also compress the image if it's too big and then save it, although quality will be lost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM