What happens when localStorage is full?

前端 未结 1 1091
盖世英雄少女心
盖世英雄少女心 2020-11-29 21:45

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

相关标签:
1条回答
  • 2020-11-29 22:22

    Firstly, some useful resources:

    • Web Storage Support Test - has a table comparing data storage quotas between browsers.
    • Simple localStorage quota test
    • Summary of localStorage browser behaviour
    • W3C spec - indicating how a user agent (e.g. browser) should behave (both localStorage and sessionStorage).

    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:

    • Opera: opera:config -> Domain Quota For localStorage
    • Firefox: about:config -> dom.storage.default_quota

    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:

    • The data is stored, overwriting values if an identical key already exists.

    If no:

    • The data is not stored and no existing data is overwritten.
    • A 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.

    0 讨论(0)
提交回复
热议问题