Logo

dev-resources.site

for different kinds of informations.

Javascript Ls/ss/cookies😎

Published at
6/27/2024
Categories
javascript
localstorage
cookies
Author
bekmuhammaddev
Categories
3 categories in total
javascript
open
localstorage
open
cookies
open
Author
14 person written this
bekmuhammaddev
open
Javascript Ls/ss/cookies😎

Browser Memory:

Image description

  • localStorage
  • Session Storage
  • Cookies

Method

SetItem();
GetItem();
RemoveItem();
Clear();

Local Storage
localStorage foydalanuvchi brauzerida ma'lumotlarni uzoq muddat saqlash uchun ishlatiladi. Saqlangan ma'lumotlar brauzer yopilgandan keyin ham saqlanadi.localStorage odatda har bir kelib chiqadigan domen uchun taxminan 5-10 MB xotira ajratiladi. Bu miqdor brauzer va qurilmaga qarab biroz farq qilishi mumkin.

Ma'lumot saqlash(SetItem):

localStorage.setItem('kalit', 'qiymat');

Enter fullscreen mode Exit fullscreen mode

cancole:

Image description

Ma'lumot olish(GetItem):

let qiymat = localStorage.getItem('kalit');
cansole.log(qiymat)
Enter fullscreen mode Exit fullscreen mode

cansole:

Image description

Ma'lumotni o'chirish(removeItem):

localStorage.removeItem('kalit');

Enter fullscreen mode Exit fullscreen mode

Barcha ma'lumotlarni o'chirish(Clear):

localStorage.clear();

Enter fullscreen mode Exit fullscreen mode

Session Storage
sessionStorage ham foydalanuvchi brauzerida ma'lumotlarni saqlash uchun ishlatiladi, lekin bu ma'lumotlar faqat sessiya davomida saqlanadi. Ya'ni, brauzer oynasi yopilganda ma'lumotlar o'chiriladi.sessionStorage ham odatda har bir kelib chiqadigan domen uchun 5-10 MB xotira ajratiladi. Bu miqdor ham brauzer va qurilmaga qarab o'zgarishi mumkin. sessionStorage faqat sessiya davomida ma'lumotlarni saqlaydi va sessiya tugashi bilan (brauzer oynasi yopilganda) ma'lumotlar o'chiriladi.

Ma'lumot saqlash:

sessionStorage.setItem('kalit', 'qiymat');

Enter fullscreen mode Exit fullscreen mode

Ma'lumot olish:

let qiymat = sessionStorage.getItem('kalit');

Enter fullscreen mode Exit fullscreen mode

Ma'lumotni o'chirish:

sessionStorage.removeItem('kalit');

Enter fullscreen mode Exit fullscreen mode

Barcha ma'lumotlarni o'chirish:

sessionStorage.clear();

Enter fullscreen mode Exit fullscreen mode

Cookies
Cookies kichik ma'lumotlar bo'lib, ular brauzerda saqlanadi va veb-saytlar tomonidan o'qilishi mumkin. Cookies maxsus muddat bilan belgilanishi mumkin va brauzer yopilganda yoki maxsus vaqt oralig'ida o'chirilishi mumkin.

Cookie saqlash:

document.cookie = "kalit=qiymat; path=/; max-age=3600"; // 1 soat davomida saqlanadi

Enter fullscreen mode Exit fullscreen mode

Cookie olish:

function getCookie(kalit) {
  let name = kalit + "=";
  let decodedCookie = decodeURIComponent(document.cookie);
  let ca = decodedCookie.split(';');
  for(let i = 0; i < ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

Enter fullscreen mode Exit fullscreen mode

Cookie o'chirish:

document.cookie = "kalit=; path=/; max-age=0";

Enter fullscreen mode Exit fullscreen mode

Image description

Xotira hajmi brauzer va platformaga qarab biroz farq qilishi mumkin. Ba'zi mashhur brauzerlarning localStorage va sessionStorage hajmlari haqida umumiy ma'lumot:

  • Google Chrome: Taxminan 10 MB.
  • Mozilla Firefox: Taxminan 10 MB.
  • Microsoft Edge: Taxminan 10 MB.
  • Safari: Taxminan 5 MB.
  • Opera: Taxminan 10 MB.
cookies Article's
30 articles in total
Favicon
Cookies auto clearing after browser refresh issue , CORS related express cookies issue
Favicon
Understanding Cookies in Rails: A Developer's Guide
Favicon
Understanding JWT Tokens vs. Session Cookies: The Best for Web Authentication
Favicon
How to use Cookies in Postman?
Favicon
Comprehensive Guide to Cookies in JavaScript
Favicon
Understanding Cookies: What They Are, How They Work, and Why They Matter for Your Privacy
Favicon
What Cookies are Important for Privacy?
Favicon
Making the most annoying cookie banners we could think of 🍪🤬
Favicon
The Most Annoying Cookie Banner Ever Hackathon 🤬🍪
Favicon
How to Set Up User Cookies and Connect Google Analytics in Your React App
Favicon
Cookie Consent Headaches Across Subdomains
Favicon
Hacking Cookies and PWA on Ubuntu
Favicon
Third-Party Cookies Are Gone (Or Not). How Can I Still Embed Cross-Site Apps?
Favicon
🍪 Cookies - A humbling auth experience
Favicon
Javascript Ls/ss/cookies
Favicon
Contextual Targeting vs Cookies: Who will win in 2024?
Favicon
Javascript Ls/ss/cookies😎
Favicon
Introduction to JWT and Cookie storage
Favicon
Demystifying Session-Based Authentication: Your Angular Roadmap
Favicon
How to persist client-side preferences on the client in Svelte (w/o DB)
Favicon
Cookies in Depth using Javascript and NodeJs
Favicon
Cross-Domain Tracking Implementation
Favicon
Double chocolate chip cookie
Favicon
Mastering Authentication & Authorization: Exploring Identity Framework with .NET 8 and Migrations
Favicon
Elixir - Simple Req Cookie Jar
Favicon
Limitations of Cookies
Favicon
Cookies vs Session Storage vs Local Storage
Favicon
Best DX for cookies on localhost
Favicon
Understanding Cookies and Sessions in Node.js
Favicon
Cookies

Featured ones: