当前位置:网站首页>On the knowledge points of cookie attributes and the differences between webstorage and cookies?

On the knowledge points of cookie attributes and the differences between webstorage and cookies?

2022-06-11 23:32:00 A-linWeb

cookie Original intention “ cookie ”, But in the computer cookie Not the original intention .Cookie It's some data , Stored in a text file on your computer .

When 【web The server 】 towards 【 browser 】 send out 【web page 】 when , After the connection is closed , The server will not record the user's information .
Cookie The purpose of this project is to solve “ How to record the user information of the client ”:

When users access web When the page is , His name can be recorded in cookie in .
The next time the user visits the page , Can be in cookie Read user access records in .

Can be JavaScript Control it ( Set up 、 Read 、 Delete )

cookie Classification and usage scenarios of ?

classification : conversation cookie And persistence cookie

conversation cookie: If cookie Does not include due date , It can be regarded as a conversation cookie. conversation cookie Stored in memory , Never write to disk . When the browser is closed ,cookie Will be lost forever

persistence cookie: If cookie Include due date , It can be regarded as persistence cookie. On the specified expiry date ,cookie Will be removed from disk .

cookie Characteristics of , advantage :

The requirements for data security are not high .
Share data across pages .
Storage space approx 4kb about

cookie The shortcomings of

1)cookie May be disabled ;
2)cookie Browser related , Can't visit each other ;(cookie Cross domain can achieve , Storage security risks )
3)cookie May be deleted by the user ;
4)cookie Security is not high enough ;
5)cookie Very small storage space , about 4kb about .

Common occasions :(1) Save user login status ;(2) Track user behavior ;(3) Custom page ;(4) Create a shopping cart … wait

cookie API

cookie Stored on the client in the form of key value pairs .

Such as :document.cookie=“key=val; expires=Thu, 18 Dec 2043 12:00:00 GMT; path=/”;

document.cookie Used to set cookie, It is best to encapsulate as a function or use a plug-in library .
expires cookie The expiration time of
path cookie The path of
domain cookie Domain name of , cookie Object's domain Property is set cookie Scope of action , If this domain does not match the domain you are currently browsing , It can be regarded as “ The third party cookie”, Will be rejected by the browser .

More attribute references :
cookie Properties of .png
 Insert picture description here

webStorage and cookie The difference between ?

webStorage Than cookie Security
webStorage Than cookie Large amount of storage
webStorage There is no need to carry... During client and server requests , and cookie need .

原网站

版权声明
本文为[A-linWeb]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011608548168.html