浏览器cookie
Cookies — the tech-related variety — have been getting a bad rap lately. But they aren’t necessarily the demons that they’ve been portrayed to be.
Çookies -科技相关的品种-已经最近获得的坏名声。 但是它们不一定是被描绘成的恶魔。
As someone recently analogized to me, cookies are like having a door-to-door salesperson stop by your home, ask you some questions such as “What is your favorite color?” and “What’s your favorite food?” and writing your responses on a Post-It note and sticking that note on your front door. Then, other salespeople who stop by can read your responses and customize their products/ads to you.
正如最近有人模仿我一样,Cookie就像是一个挨家挨户的推销员在您家门口停下来,问一些问题,例如“您最喜欢的颜色是什么?” 和“您最喜欢的食物是什么?” 并将您的回复写在便利贴上,然后将其贴在前门上。 然后,其他路过的销售人员可以阅读您的回复并为您定制产品/广告。
Cookies encountered in browsers act similarly to that Post-It note. Companies and organizations use cookies to target and collect your preferences for product-placement and advertising purposes. They acquire your online preferences from studying your browser-based actions the sites you visit, searches you conduct, etc. On a technical level, cookies are merely key-value pairs stored within your internet browser. These are kept on file, so to speak, in the browser until the cookie expires.
在浏览器中遇到的Cookie的行为类似于该便笺。 公司和组织使用Cookie来定位和收集您对产品放置和广告目的的偏好。 他们通过研究您基于浏览器的操作,访问的网站,进行的搜索等来获得您的在线偏好。在技术层面上,Cookie只是存储在您的Internet浏览器中的键值对。 可以说,这些文件一直保存在浏览器中,直到cookie过期。
Besides the cookies that are associated with browsing habits, the most common example of a cookie is the shopping cart feature on an e-commerce site.
除了与浏览习惯相关的cookie外,cookie的最常见示例是电子商务网站上的购物车功能。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/7fa3a58288d392d9507f5639eb07de84.png)
Let’s say that you’ve found a book on Barnes and Noble’s website that you want to buy. You add the book to your cart and are then given a visual indicator that your cart now contains one item.
假设您在Barnes and Noble的网站上找到了要购买的书。 您将书籍添加到购物车中,然后获得一个视觉指示器,表明您的购物车中现在包含一项。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/954961e4214f9679c7a174ee8f485e29.png)
Perhaps you’re unsure whether you want to buy the book and decide to think about it for a while. You leave the Barnes and Noble site, thus abandoning your cart, and navigate to your favorite news website. After reading the news, you decide that you really do want that book after all. So, back to the Barnes and Noble site you go, fully prepared to search again for the book and add it to your cart.
也许您不确定是否要购买这本书并决定考虑一会儿。 您离开了Barnes and Noble网站,从而放弃了购物车,并导航到您最喜欢的新闻网站。 阅读新闻后,您确定您确实确实想要那本书。 因此,回到您的Barnes and Noble网站,已经做好充分的准备,可以再次搜索该书并将其添加到购物车中。
Except that, when the page loads, you immediately notice the shopping cart icon because it shows that there’s an item in your cart already. After clicking the cart, you see that it is the book that you’d wanted. While it wouldn’t have been too laborious to search for and place the book into your cart again, it’s helpful that Barnes and Nobel remembered that you were interested in buying this book, enabling an even faster checkout.
除此之外,在页面加载时,您会立即注意到购物车图标,因为它显示您的购物车中已经有商品。 单击购物车后,您会看到它是您想要的书。 虽然搜索和将书重新放入购物车都不会太费力,但Barnes和Nobel记得您有兴趣购买这本书是很有帮助的,从而可以更快地结帐。
So, how did the Barnes and Noble site know to keep that particular book inside the shopping cart? A cookie, of course! When you first visit the site, a request is sent to the Barnes and Noble website server. When it responds to your computer, it sets a cookie to capture your unique user information. As a result, things such as your cart contents are captured for the duration of your browsing session, which is the actual term used to describe this duration. In other words, as long as you keep your browser open and don’t close out of it, the cookie will remain active and remember your cart’s contents until the cookie’s set expiration date.
那么,Barnes and Noble网站如何知道将特定书籍保留在购物车中? 当然是Cookie! 首次访问该站点时,会将请求发送到Barnes and Noble网站服务器。 当它响应您的计算机时,它会设置一个cookie来捕获您的唯一用户信息。 结果,在您的浏览会话持续时间内捕获了诸如购物车内容之类的东西,这是用于描述该持续时间的实际术语。 换句话说,只要您保持浏览器打开并且不关闭浏览器,cookie就会保持活动状态并记住您购物车中的内容,直到cookie设置的到期日期为止。
Below is a list of cookies identified from Barnes and Noble’s website. The green box highlights a single cookie’s information. Among the cookie’s details are the value assigned to the specific cookie, the domain to which it is attached, its specific path in the URL, and its expiration date.
以下是从Barnes and Noble网站识别的Cookie列表。 绿色框突出显示单个cookie的信息。 Cookie的详细信息包括分配给特定Cookie的值,其附加到的域,URL中的特定路径及其到期日期。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/cd7c92886440ceecb481e3c4402418e6.png)
I used an extension to access this list, but you can easily access the web page’s cookies list via the “Application” view in the developer tools.
我使用扩展名来访问此列表,但是您可以通过开发人员工具中的“应用程序”视图轻松访问网页的cookie列表。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/203e6b216b1e4f03f396e71abb6f8fbc.png)
Cookie的类型 (Types of Cookies)
Cookies are divided into two categories: “First-party cookies” and “third-party cookies”.
Cookie分为两类:“第一方Cookie”和“第三方Cookie”。
First-party cookies aim to provide a better user experience for users while they browse the web. They can store passwords and capture a user’s location and other details to enable easier and faster information retrieval.
第一方Cookie旨在为用户浏览网络时提供更好的用户体验。 他们可以存储密码并捕获用户的位置和其他详细信息,从而可以更轻松,更快地检索信息。
Third-party cookies, on the other hand, are the ones responsible for giving cookies the bad press they have been receiving. They typically involve tracking the user as they browse. This tracking can manifest via “ad retargeting”, which is essentially tailoring ads to the user based on the sites visited by the user. Another popular third-party cookie function utilizes social media plug-ins, which in turn enable the social media site to follow you as you peruse the internet. Information obtained from these types of cookies include not only the sites you visit but also details such as your location, the type of device that you’re using to access the site, etc.
另一方面, 第三方cookie是导致cookie受到不良影响的原因。 它们通常涉及在浏览时跟踪用户。 这种跟踪可以通过“广告重新定位”来体现,它实际上是根据用户访问的网站为用户量身定制广告。 另一个流行的第三方cookie功能使用社交媒体插件,当您仔细浏览Internet时,社交插件可以使社交媒体网站跟随您。 从这些Cookie类型获得的信息不仅包括您访问的站点,还包括诸如位置,用于访问该站点的设备类型之类的详细信息。
For companies using third-party cookies to track users’ behaviors and other information, it all boils down to making more money. So while you the user can not accept that cookies are used on a certain site, the company may not let you view their site in return.
对于使用第三方Cookie来跟踪用户行为和其他信息的公司而言,这一切都可以归结为赚更多钱。 因此,尽管您不能接受用户在特定站点上使用cookie,但是公司可能不会让您查看其站点。
On one hand, cookies can be viewed as very helpful when browsing and communicating on the internet. On the other hand, what a site does with the information it collects via cookies can perpetuate their negative reputation. At the end of the day, the least a user can do is to be informed about cookies and things to look for when surfing the internet.
一方面,在Internet上浏览和交流时,cookie被视为非常有用。 另一方面,网站如何处理通过Cookie收集的信息可能会使他们的负面声誉永久化。 归根结底,用户要做的至少是要了解有关cookie和浏览互联网时要查找的内容的信息。
翻译自: https://medium.com/swlh/browser-cookies-foe-or-friend-703c23772ca3
浏览器cookie