Cookies are small files that a website saves on your computer in order to remember your preferences for it (and choices regarding cookies). They can be used to remember what you have visited, how you have interacted with the website, and even to track which pages you visit most often. Some websites use cookies in order to improve the user experience. For example, if a website knows that you have visited it before, it may show you more relevant content or offer you a different experience if you visit again. Other websites use cookies in order to track user activity on the website in order to improve the overall performance of the site. For example, if a website knows that users are visiting it more often than usual, it may make changes to the content or layout of the site in order to better match what users are interested in.
How do websites remember your preferences for them (or desire for none), and what about the touchy subject of cookies themselves? Today’s SuperUser Q&A post seeks to shed some light on how cookies work and the information they store for a confused reader.
Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.
Photo courtesy of Pedro Vezini (Flickr).
The Question
SuperUser reader Ruud Lenders wants to know more about how preferences and cookies for websites work:
How does a website remember your preferences for it overall and about your choices regarding cookies in general?
This also got me to thinking. How can a website remember if it is allowed to store cookies? By storing it in a cookie?
The Answer
SuperUser contributor bvukelic has the answer for us:
Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.
Inspecting Cookies Set for a Particular Page
In Firefox, you can list cookies for a particular web page by right-clicking a blank part of the page, then selecting the View Page Info option. You will find a View Cookies button in the Security Tab. In Chrome, you have the same View Page Info option which opens a dialog that hangs from the address bar. A link near the top will take you to a listing of cookies. I assume similar features can be found in other browsers.
Discovering if a Website Sets a Cookie
Here is one way that you can discover what the website is doing. Visit the website in Incognito Mode. Open the Developer Tools and switch to the Network Tab. Then check to see what activity is occurring in the background as you decline having the site track you with cookies. Specifically, look for response headers and see if there are any Set-Cookie headers in there. Then try deleting cookies mentioned in the header to see if that makes any difference.
About localStorage
Since another poster has mentioned localStorage (in-browser database), I will comment on this as well. I think it will be very rare that a website uses localStorage for this purpose as localStorage data is not accessible to the server unless there is JavaScript code that sends the data back to the server. If you wish to check the contents of localStorage, the fastest way is to open the Developer Tools in your browser, go to the (JavaScript) Console Tab, and type localStorage. This should give you an output that looks something like:
Storage { someKey: “value”, length: 1 }
The someKey identifies the value set by JavaScript on the web page you are on. If you believe someKey does something relevant, you can try removing it by running the following:
localstorage. removeItem(‘someKey’);
This removes the data under someKey from localStorage, and reloading the web page may restore it to factory settings. If you are not sure the particular key is set by the cookie notification functionality, you may open the web page in Incognito Mode and list the contents of localStorage before interacting with the web page.
Again, I doubt many websites use localStorage for this purpose.