Understanding Client-Side Storage

dipakkr

Deepak Kumar

Posted on October 23, 2020

Understanding Client-Side Storage

Why do we need clientSide storage?

Do you know why all websites show these popup to accept cookie policy?

Alt Text

Because they want your permission to save user-specific data to store/access cookies in your browser. The browser has some storage limit which websites use to personalize user experience.

Features of clientSide data storage

  • data persistence which means you won't lose the data on page reload or on closing the browser. This property helps in personalizing the user experience on the app.

  • Different websites can have different clientSide data(i.e cookie, session, and localStorage).

Types of ClientSide Storages


1. localStorage

It's a key-value pair type client-side storage. It offers a maximum of 5MB limit. At 91wheels, we are using localStorage to store user-specific information like current city and user name for better personalization.

Pros

- Data has no expiry time. However, it can be removed by end-users by clearing browser data.

Cons

  • The stored data is in plain-text. Hence, it's not advisable to store critical user information in localStorage.
  • It can only be read on the client-side.

How to save data to localStorage:

localStorage.setItem('username', 'dipakkr');

Enter fullscreen mode Exit fullscreen mode

Retrieving data from localStorage:

const data = localStorage.getItem('username');

console.log(data); // dipakkr

Enter fullscreen mode Exit fullscreen mode

localStorage

2. Session Storage

Features

  • It stores data only for a particular session. Session means till the time the browser tab is not closed. Once you close the browser, sessionStorage will be auto-deleted.

  • Like localStorage, it can only be accessed from the client. This also means that data is never transferred to the server.

  • Session storage also works as a key-value pair type storage.

  • The maximum limit of data saving in SessionStorage is about 5 MB.

3. Cookie

  • Cookies are the earliest form of clientSide data storage. It is used to store information to personalize user experience on websites.

  • The size of the cookie must be less than 4KB.

  • Expiry time can be defined in the cookie.

Alt Text


Let's connect on Twitter

πŸ’– πŸ’ͺ πŸ™… 🚩
dipakkr
Deepak Kumar

Posted on October 23, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

A Roadmap to Growth in the IT Industry
Architecting Your Own Database - Part 1
javascript Architecting Your Own Database - Part 1

November 1, 2024

Prisma ORM
undefined Prisma ORM

October 21, 2024

Common Myths About Mongoose
javascript Common Myths About Mongoose

November 9, 2024

How to use Prisma Postgres πŸš€
prisma How to use Prisma Postgres πŸš€

October 31, 2024