HTML5 中的本地存储、会话存储、Web 存储、Web 数据库和 cookie
这些概念之间有什么区别?我什么时候应该特别使用它们?此列表是否还包含同一一般概念的不同名称?
- HTML5 本地存储
- HTML5 会话存储
- HTML5 Web 存储
- HTML5 Web 数据库
- Cookie
What is the difference between these concepts, and when should I use one in particular? Does this listing also contain different names for the same general concept?
- HTML5 local storage
- HTML5 session storage
- HTML5 web storage
- HTML5 web database
- Cookies
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
HTML5 Web 存储是新的客户端数据存储选项的通用总称。
本地存储是持久的并且范围仅限于域。目前,通常会提到两种风格:
会话存储是非持久性的,且范围仅限于当前窗口。
Cookie 是完成上述所有操作的老式方法。存储每个域的名称/值对。
HTML5 web storage is a generic umbrella term for the new client-side data storage options.
Local Storage is persistent and scoped to the domain. At the moment two flavors are usually mentioned:
Session Storage is non persistent and scoped only to the current window.
Cookies are the old school way of doing all of the above. Stores name/value pairs per domain.
我想添加更多信息:
cookie 只能存储 4k 数据
而
localStorage
能够存储 5mb 的数据(取决于浏览器)网站将在浏览器中保存 cookie,下次浏览器将将该
cookie
与 http 请求一起发送给服务器-边。 Cookie 旨在与服务器一起使用。使用
localStorage
,您可以存储更多数据,但默认情况下仅限于客户端。I would like to add more information:
cookies are able to store only 4k of data
whereas
localStorage
is able to store 5mb of data (Depending on browsers)Websites will save cookies in browsers and next time browser will send that
cookie
along with http request to be used server-side. Cookies are meant for being used with the server.With
localStorage
, you can store more data, but it is restricted to the client by default.会话存储:会话存储是在用户执行单个事务的情况下引入的,但可以同时在不同窗口中执行多个事务。一旦关闭窗口,会话就会终止。
本地存储:本地存储是特定于域的,被引入到跨多个窗口。没有像Cookies那样的时间限制,并且可以存储最多5MB的存储,例如用户邮箱等......
Session Storage:Session storage is introduced where the user is carrying out a single transaction, but could be carrying out multiple transactions in different windows at the same time.Session is terminated once we close the window.
Local Storage:Local storage is specific to domain and is introduced to span across multiple windows.There is no time limit as in the case of Cookies,and can store upto 5MB storage such as Users MailBox etc....
AFAIC:
AFAIC:
如果您的用户位于欧洲,需要考虑的另一件大事是 Cookie 在欧洲是非法的。 https://www.sitepoint.com/europe-website-cookie-privacy-法律/
Another big thing to consider if your users are located in Europe, is that Cookies are illegal in Europe. https://www.sitepoint.com/europe-website-cookie-privacy-law/