JavaScript Cookies

You are Here:

What are Cookies?

Cookies are bits of data that are sent back and forth between a client (usually a browser) and a server for each request and response.

Where Cookies are Stored?

Cookies are stored as a text file in your hard disk.

Some browsers like Chrome will store cookies from each domain in a separate file. Whereas, some browsers like firefox stores all cookies in a same file.

Purpose of Cookies

Nowadays cookies are used for several purposes, but, two of the most common reasons Web developers use cookies are

  • To identify visitors: You can detect when a user has previously visited your site and customize what that user sees on subsequent visits.
  • To save transaction state: When filling out a lengthy form it is recommended to store the user typed value in a cookie because when a power cut or reload occurs you can refill the user typed value from the cookie when the user revisits that particular page.

Cookies Limitation

The limitations of cookies as follows

  • Length: Each domain is allowed to store 20 cookies (minimum) to 50 cookies (maximum).
  • Expiry: There is no official time limitation for cookie expiry. You can set it to expire in a second, hour, month, year, or even decades. It is to be noted that user can delete your cookies without any restriction.
  • Size: Some browsers like chrome, firefox have no size limitation and other browsers like Internet Explorer, Opera, Safari allows 4,096 bytes to store. So you are recommended to limit the size of your individual cookie to 4kb.

Demo

Login Form
User Name
Password
Log in

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author