HTML5 中的本地存储、会话存储、Web 存储、Web 数据库和 cookie

发布于 2024-10-25 02:22:33 字数 167 浏览 6 评论 0原文

这些概念之间有什么区别?我什么时候应该特别使用它们?此列表是否还包含同一一般概念的不同名称?

  • 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

合约呢 2024-11-01 02:22:33

HTML5 Web 存储是新的客户端数据存储选项的通用总称。

本地存储是持久的并且范围仅限于域。目前,通常会提到两种风格:

  • “默认”:以名称/值对的形式存储内容
  • Web SQL(又名 Web 数据库):使用 SQL 数据库

会话存储是非持久性的,且范围仅限于当前窗口。

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:

  • 'default': stores things in name/value pairs
  • Web SQL (aka Web Database): uses an SQL database

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.

如此安好 2024-11-01 02:22:33

我想添加更多信息:
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.

漆黑的白昼 2024-11-01 02:22:33

会话存储:会话存储是在用户执行单个事务的情况下引入的,但可以同时在不同窗口中执行多个事务。一旦关闭窗口,会话就会终止。

本地存储:本地存储是特定于域的,被引入到跨多个窗口。没有像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....

南巷近海 2024-11-01 02:22:33

AFAIC:

  1. Cookie 为每个 cookie 4k,本地存储为每个域 5k。
  2. Cookie 的存在时间限制和存储只是客户端协议和域特定的数据容器。

AFAIC:

  1. Cookies are 4k per cookie, and local storage is 5k per domain.
  2. Cookies existance time limits and sorage is just client-side protocol- and domain-specific bin for data.
暮色兮凉城 2024-11-01 02:22:33

如果您的用户位于欧洲,需要考虑的另一件大事是 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文