You are on page 1of 12

Cookies

Interviewquestion-59

Follow on
@Duvvuru Kishore
what we will learn when we move
across slides?

What are cookies?


Second ,we will go with an
example to understand why we
need cookies ?
Where Are Cookies Used?
How do cookies work?
Types of Cookies?
Difference between cookies and
(local and session storage)
What Are Cookies?
Cookies are small pieces of data that websites
send to your web browser (like Chrome,
Firefox, or Safari) when you visit them. These
pieces of data are stored on your computer or
device.
Example to understand why the need of
cookies?

Think of a website as a library. You visit this library to


read books (web pages). The librarian (the website)
would like to remember things about you, like your
name and the books you've read. But the librarian
meets so many people that they can't remember
everyone.
That's where cookies come in. Cookies are like
notes that the librarian gives you when you arrive
at the library (visit a website). These notes have
tiny bits of information, such as your name or the
last book you read.

When you return to the library later (visit the


website again), the librarian checks the note
(cookie) and says, "Oh, it's you!

Cookies are like library card because they make


your visits to the library (website) more convenient.

Cookies also help the librarian (website) know how


many people visit the library and which books are
popular, which can be important for making the
library better(website better)..
Where Are Cookies Used?

Remembering Information: Cookies help websites


remember your preferences. For example, your login status
on a site, language preference, or items in your shopping
cart on an online store.

Tracking and Analytics: Websites use cookies to track user


behavior and gather data for analytics, helping them
understand how users interact with their site.

Personalization: Cookies enable websites to provide


personalized content, like tailored recommendations,
based on your past interactions.

Session Management: Cookies can help manage your


session on a website, ensuring you stay logged in while you
navigate the site.
How Do Cookies Work?

When you visit a website, the website's server sends


a cookie to your browser. Your browser stores this
cookie for later use.

The cookie contains information, like your


preferences, site settings, login status, and more.

we can accept or deny or customize the cookies


based on your need
Types of Cookies:

Session Cookies: These are temporary cookies that are


stored only during your current browsing session. They
are removed when you close your browser.

Persistent Cookies: These cookies remain on your device


for a specified period, even after you close your
browser. They are often used for long-term preferences
and tracking.
In interviews there will not go much deeper than this,
In projects perspective you have to deep dive into
code. practice it to make yourself pro
Difference between cookies and
(local and session ) storage

Cookies:

Size & Use: Store small data (up to 4KB), commonly for
session IDs, authentication, and preferences.

Lifespan: Can have an expiry date or be session-based,


persisting until the browser is closed.

Transmission: Sent with every HTTP request, affecting


performance.
Local Storage:

Size & Use: Can store larger amounts (up to 5MB), suitable
for settings, cache, and persistent data.

Lifespan: Persists after closure, not cleared unless removed


manually.

Session Storage:

Size & Use: Similar capacity to local storage, intended


for temporary session-specific data.

Lifespan: Cleared when the tab is closed, ideal for short-


term data needs within a browsing session.
Follow on
@Duvvuru Kishore

You might also like