What is a cookie?

Nirmal Joshi
3 min readJun 29, 2022

--

Many of us have heard about cookies, local storage, and session storage but do you know what they are exactly? Let me explain them to you in the simplest of ways…

Whenever you open certain sites, they show pop-ups or info tabs saying- “this site uses cookies and you must accept them all/partly to continue browsing the site”.

I am sure you have encountered numerous such websites that flash that information, even before you browse that particular site.

So what are they? They are called cookies.

Cookies are just small text files that are placed on your (user’s) device. They hold a very small amount of data with a max capacity of just 4KB. They are used for various purposes such as storing pages visited on a site or a user’s login information so that they do not have to re-enter their credentials every time.

Cookies play a very important role in customizing the user experience based on the user’s browsing history for that site.

A Cookie can be set from an HTTP header. Usually, the server that you’re trying to reach, if it has cookies, will send an HTTP header like this:

Set-Cookie: this_is_a_cookie=sample_cookie

When your browser receives this header, it saves the this_is_a_cookie Cookie.

Remember! Cookies are associated with websites. You can only see the cookies of the website you are browsing.

To see the cookies you have, if you have Firefox, from your devtools, go to storage > Cookies; if you have Chrome, from your devtools, go to Application > storage > Cookies.

As I mentioned, the max size for cookies is 4KB. Because cookies are being sent all the time — you don’t want to send large cookie data to the requests when visiting a page. Let me tell you, even with this small size cap, you should minimize cookies as much as possible to make your site faster.

You can use Javascript to create cookies with document.cookie.

document.cookie = “this_is_a_cookie=sample_cookie”;
console.log(document.cookie);

For a long time, cookies were the main way to store information about users. This scenario changed after HTML5 came into existence and introduced LocalStorage as another data storage option. I will explain the difference between local storage and cookies in another video. You can ask any questions related to cookies in the comment section.

Looking for remote/contract Web/UI/Full stack opportunities in the US? Connect with the leading staffing experts of the industry today.

About me:

Founder and CEO of an IT company in India, I have more than 25 years experience of in dealing with people, processes, and codes. I started online training for my students when it was not in fashion and have trained more than 1000 students/working professionals personally which has helped them to secure awesome jobs or even start their own businesses.

Check out my Udemy profile to know more about the courses that I teach.

I am also been an active corporate trainer for several years now and have been consulting with top Fortune 500/1000 companies to streamline their development projects efficiently. My goal is to share knowledge with a primary focus on advanced tools & techniques, projects, and standard programming practices to help my students understand the basics and fundamentals and make awesome technological implementations.

--

--

Nirmal Joshi
Nirmal Joshi

Written by Nirmal Joshi

A founder and CEO of an IT company in India, I have more than 22+ years’ experience of dealing with people, processes and codes.

No responses yet