我正在使用浏览器缓存来存储响应数据,但想知道将数据存储在浏览器缓存中的可行性如何。谁能解释一下:
1. Is their a guarantee that the data will be cached for specific time, if I am storing only JSON data(can be huge).
2. What is the maximum size limit of browser cache.
3. Is my data cross domain accessible?If yes is their a way I can protect it?
4.Does the result vary from browser to browser?
最佳答案
现代浏览器中有两种主要的存储方法,localStorage
和sessionStorage
,在您的情况下,我假设您使用localStorage
。
对于本地存储
:
- 只要用户不清除数据或者您使用
localStorage.removeItem()
删除数据,存储的数据就会一直存在 localStorage
的最大大小因浏览器而异,基本上至少是2.5MB。详情见this postlocalStorage
的工作方式与 cookie 类似,因此您不想存储任何敏感内容,建议客户端和服务器之间使用SSL
- IE 8 及更高版本、Chrome 4、Firefox 3.5、Opera 10.5 和 Safari 4 已实现此 API
此link中有关localStorage
的详细信息
关于javascript - 与浏览器缓存相关的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18757176/