当localStorage已满时会发生什么? [英] What happens when localStorage is full?

查看:1613
本文介绍了当localStorage已满时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到关于缓存行为的文章,所以我只能假设它没有太大的不同,但我想确保。

我已经读过,大多数浏览器有5MB(给或拿)localStorage,我是intrested浏览器的行为是什么?



我明白每个浏览器的行为不同,但我主要在Safari,Chrome和Firefox中感兴趣(因为那些是我认为的作为浏览器)。


  • 上面提到的浏览器是否会从我的网站上删除数据,或者会选择最老的还是某种类型的?

  • 在这种情况下我的物品会被保存吗?



:b
$ b


  • 可以说我滥用localStorage和我的网站试图使用它,并在同一页
    我正在填充它,并试图保存更多,我会得到一个警告会发生这种情况或以某种方式保存在内存中 getItem 返回null


  • 如果我尝试保存大于localStorage大小的项目,会发生什么情况?

    已解答: answer can找到这里

  • 是否可以从sessionStorage中得到相同的确切的行为,这应该是相同的吗?

  • ul>

    我知道这是很多问题,但我试图理解所有与这个主题有关的东西,我会感谢你能回答的问题的任何部分。 / p>

    Regards。

    解决方案

    首先,介绍一些有用的资源:




    • Web
      Storag e Support Test(支持测试)
      - 有一个表格,用于比较浏览器之间的数据存储配额

    • 简单
      localStorage配额测试

    • localStorage浏览器行为摘要

    • W3C规范 - 指示用户代理(如浏览器)应该表现出来(localStorage和sessionStorage)。


      在回答你的问题时,桌面浏览器往往有一个初始的最大localStorage配额每个域5MB。在某些情况下,用户可以对此进行调整:


      • Opera:opera:config - >域名配额localStorage

      • Firefox:about:config - > dom.storage.default_quota



      在Chrome中,似乎没有尽管像Opera,localStorage数据可以使用开发工具在每个域直接编辑。



      当您尝试在localStorage中存储数据时,浏览器检查当前域是否有足够的剩余空间。
      如果是:


      • 存储数据,如果已经存在相同的密钥,则覆盖值。如果不是:


        • 数据不存储,也不存在现有数据被抛出。

        • 引发了 QUOTA_EXCEEDED_ERR 异常



        在这种情况下, getItem(key)将返回成功存储的最后一个值(如果有的话)。

        (Opera略有不同,它会显示一个对话框,让用户选择增加当前域的存储空间。)注意sessionStorage和localStorage都是相同的存储对象的实现,所以他们的行为是相似的,错误处理是相同的。


        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 intrested in what would be the behaviour of the browsers?

        I understand every browser acts diffrently but i'm intrested mostly in Safari, Chrome and Firefox (as those are the ones i consider as browsers).

        • Will the browsers mentioned above delete data from my website or it will choose "the oldest" or something of the sort?
        • Will my item be saved in such case?

        And the most important :

        • Lets say i "abuse" the localStorage and 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 AND will the getItem return null when this happens or it somehow saved in memory?

        • What happens if i try and save an item larger then the localStorage size?

          Answered : answer can be found here

        • Is the same exact behaviour can be expected from sessionStorage which allegdly should be the same?

        I know this is alot of questions but i'm trying to understand all that's related to the subject, i'd be thankfull for any part of the question you can answer.

        Regards.

        解决方案

        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:

        • 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.

        这篇关于当localStorage已满时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆