session and cookie usage scenarios and differences

 cookie stored in the client, session stored in the server.

    Of the cookie is to interact with the server as part of the http present specification, the web storage is local storage to the "Data" born.

    cookie scenarios: ① determine whether the user is logged on site; ② cart used to record or record user preferences to develop a push;

    session scenarios: ① login authentication information

 A cookie is a website to indicate the user identity and data stored on the user's local terminal (Client Side) are (usually encrypted).

 cookie data is always carried in the http request homologous in (even if not needed), note passed back and forth between the browser and the server.

 sessionStorage and localStorage not automatically send data to a server, saved only locally.

 

    Different validity:

 localStorage: to store persistent data, the browser is closed after data is not lost unless the initiative to delete data;

 sessionStorage: data is automatically deleted after the current browser window is closed.

 cookie: cookie valid until the expiration time set, even if the window or browser is closed

 

    Different scopes:

    sessionStorage: not shared in different browser windows open, even if the same page

    localStorage: homologous page sharing

    cookie: page sharing homology

 

 Storage size:

 cookie data size can not exceed 4k

 Although sessionStorage and localStorage storage size is also limited, but is much larger than the cookie, you can reach 5M or greater.

Guess you like

Origin www.cnblogs.com/flyerya/p/11311432.html