What if the localstorage capacity exceeds? Questions from an interview

in the interview question of one of the three major factories more than half a year ago, the interviewer asked what to do if the capacity was found to exceed when writing localstorage (that is, the general standard of 5m). At that time, he was rather nervous and confused. Now, without the help of other storage conditions, if you want to forcibly write your own data, is it possible to call a localstorage.clear () to clear the user"s other localstorage after an error is detected? Then write your own data (of course, it feels very violent and qj users) and ask for advice. Few people on google and Baidu have mentioned this need.

Mar.09,2021

localstorage storage is not 5m, but 5m per domain exceeds the request for other domains / modify ng configuration postmessge communication to access other domains
it is not good to delete other people's data. It seems that it can be understood that it can not be saved, then simply do not save.


here are two links worth looking at:

https://www.raymondcamden.com.

https://stackoverflow.com/que.

if you don't have time to read it, make a brief conclusion:

what will the
browser do when there is not enough space:

  • does not store data and does not overwrite existing data.
  • throws a QUOTA_EXCEEDED_ERR exception.

what do we do as developers:

  • almost all client storage options are very poor in terms of quotas. It deserves attention.
  • needs to track client storage usage. For example, if you saved the last 10 searches for later display to the user, please know and write it down somewhere so that when you use client storage in the future ("Hey, can we cache some fonts?") you can check and view the stored content and see if the limit may have been reached.
  • try/catch everything, okay? Well-maybe;) "Super strict makes everything perfect"-yes, but "I live in the real world"-may be excessive. Again, as long as you follow what you are doing, I think you will be all right.

I am the subject of the question. Thanks to the boss upstairs for his advice. Because I haven't found a suitable keyword before, I can't find a good answer all the time. After being mentioned by the boss, I found that there is a cross-domain write and read operation in localstorage. Let's find a reliable practice tutorial localstorage to achieve cross-domain reading and writing

.
Menu