I have found articles regarding cache behaviour so I can only assume that it's not much different but I wanted to make sure.
I have read that most browser have 5MB (give or take) for localStorage and I was interested in what would be the behaviour of the browsers?
I understand every browser acts differently but I'm interested mostly in Safari, Chrome and Firefox (as those are the ones I consider as browsers).
And the most important :
Lets say I "abuse" the localStorage on my website trying to use it all up, and in the same page I'm filling it up and trying to save more. Will I get a warning? Will the getItem
return null
when this happens or is it somehow saved in memory?
What happens if I try and save an item larger than the localStorage
size?
Answered: answer can be found here
I know this is a lot of questions but I'm trying to understand all that's related to the subject, I'd be thankful for any part of the question you can answer.
LocalStorage should be avoided because it is synchronous and will block the main thread. It is limited to about 5MB and can contain only strings. LocalStorage is not accessible from web workers or service workers. Cookies have their uses, but should not be used for storage.
localStorage is similar to sessionStorage , except that while localStorage data has no expiration time, sessionStorage data gets cleared when the page session ends — that is, when the page is closed.
Local Storage data will not get cleared even if you close the browser. Because it's stored on your browser cache in your machine. Local Storage data will only be cleared when you clear the browser cache using Control + Shift + Delete or Command + Shift + Delete (Mac)
When you clear your localStorage and fill it right after, it kind of restore the previous content and adds you new item to it. When you clear your localStorage and doing a hardrefresh, it is empty and you can start filling it again.
Firstly, some useful resources:
In answer to your question, desktop browsers tend to have an initial maximum localStorage quota of 5MB per domain. This can be adjusted by the user in some cases:
In Chrome, there doesn't seem to be a way for the user to adjust this setting although like Opera, localStorage data can be edited directly per domain using the Developer Tools.
When you try to store data in localStorage, the browser checks whether there's enough remaining space for the current domain. If yes:
If no:
QUOTA_EXCEEDED_ERR
exception is thrown.In this case, getItem(key)
will return the last value that was successfully stored, if any.
(Opera is slightly different in that it displays a dialog box giving the user the choice of increasing storage space for the current domain.)
Note that sessionStorage and localStorage are both implementations of the same Storage object so their behaviour is similar and error handling is the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With