Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

浏览器存储 #39

Open
zonglang opened this issue Jul 29, 2019 · 0 comments
Open

浏览器存储 #39

zonglang opened this issue Jul 29, 2019 · 0 comments

Comments

@zonglang
Copy link
Owner

zonglang commented Jul 29, 2019

  • Cookie 的本职工作并非本地存储,而是“维持状态”
  • Web Storage 是 HTML5 专门为浏览器存储而提供的数据存储机制,不与服务端发生通信
  • IndexedDB 用于客户端存储大量结构化数据

Cookie

Cookie的本质工作是给HTTP请求维持状态

cookie的生成方式

1. http的response中的set-cookie
2. js使用document.cookie以键值对的形式展示,一次设置一条,可设置domain、path、过期时间等 

cookie的缺陷

1. 不够大,限制再4KB左右(每个键值对的value的限制)
2. http请求的性能浪费
3. 安全性问题(CORS)

Web Storage

HTML5中新增的本地存储解决方案
LocalStorage用于持久化本地存储
SessionStorage只存在与当前tab页的会话存储
特点:

1. 大小为5M左右
2. 仅在客户端使用,不和服务端进行通信
3. 接口封装较好

IndexedDB

用于客户端存储大量结构化数据(包括文件和blobs)
使用索引实现高性能搜索

1. 异步
2. 大存储
3. 键值对存储,可存对象,二进制
4. 支持事务

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant