JavaScript_Client-side_storate

2018-05-21  本文已影响0人  钨丝灯

Client-side_storate

Modern web browsers support a number of ways for web sites to store data on the user's computer — with the user's permission — then retrieve it when necessary. This lets you persist data for long-term storage, save sites or documents for offline use, retain user-specific settings for your site, and more. This article explains the very basics of how these work.
现代浏览器支持一种或多种方式在用户允许的情况下将web网站的数据保存到用户计算机上,然后当需要的时候取出数据。这让你可以将数据长时间保存,保存网站或者文档离线使用。保存我们的网站的特殊设置,还可以进行更多操作,这篇文章非常基础的讲解了客户端存储怎样工作。


Prerequisites: JavaScript basics (see first steps, building blocks, JavaScript objects), the basics of Client-side APIs
Objective: To learn how to use client-side storage APIs to store application data.



少了一部分,直接到细节


Old fashioned: cookies

The concept of client-side storage has been around for a long time. Since the early days of the web, sites have used cookies to store information to personalize user experience on websites. They're the earliest form of client-side storage commonly used on the web.

Because of that age, there are a number of problems — both technical and user experience-wise — afflicting cookies. These problems are significant enough that upon visiting a site for the first time, people living in Europe are shown messages informing them if they will use cookies to store data about them. This is due to a piece of European Union legislation known as the EU Cookie directive.

For these reasons, we won't be teaching you how to use cookies in this article. Between being outdated, their assorted security problems, and inability to store complex data, there are better, more modern ways to store a wider variety of data on the user's computer.

The only advantage cookies have is that they're supported by extremely old browsers, so if your project requires that you support browsers that are already obsolete (such as Internet Explorer 8 or earlier), cookies may still be useful, but for most projects you shouldn't need to resort to them anymore.

Why are there still new sites being created using cookies? This is mostly because of developers' habits, use of older libraries that still use cookies, and the existence of many web sites providing out-of-date reference and training materials to learn how to store data.

过去流行的使用:Cookies

客户端存储的概念已经存在很长时间了。从网络的早期开始, 网站就使用 cookie 存储信息, 以个性化网站上的用户体验。它们是 web 上最早的客户端存储通用形式。

由于这个时代, cookies无论是技术上还是用户体验上的问题。这些问题很重要, 当第一次访问一个网站时, 生活在欧洲的人们会显示消息, 告知他们是否会使用 cookie 存储有关它们的数据。这是由于欧洲联盟的一项立法被称为EU Cookie directive(欧盟曲奇指令)。

基于这些原因, 我们不会教你如何在本文中使用 cookie。在过时、各种安全问题以及无法存储复杂数据之间, 有更好的、更现代的方法来在用户的计算机上存储更广泛的数据。

cookie 的唯一优点是它们受非常旧的浏览器支持, 因此如果您的项目需要支持已经过时的浏览器 (如 Internet 资源管理器8或更早版本), cookie 可能仍然有用, 但对于大多数项目, 您不需要再求助于他们了

为什么仍然有新的网站正在使用 cookie 创建?这主要是因为开发人员的习惯, 使用仍然使用 cookie 的旧库, 以及许多网站的存在, 这些网站提供过时的参考和培训材料来学习如何存储数据。

New school: Web Storage and IndexedDB

Modern browsers have much easier, more effective APIs for storing client-side data than by using cookies.

新学校:Web Storage and IndexedDB

现代浏览器拥有比使用 cookie 更容易、更有效的 api 来存储客户端数据。

单词记录

其他

url:https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Client-side_storage

上一篇 下一篇

猜你喜欢

热点阅读