localStorage a replacement for cookies?

2019-04-13 00:55发布

Is the newly introduced localStorage facility in html5 a replacement for cookies? Does localStorage help in making the http from stateless to stateful. Or is the localStorage an addition to the cookies.
Do you still need to use cookies to track the user or even that can be done ny localStorage?

2条回答
放荡不羁爱自由
2楼-- · 2019-04-13 01:45

Local Storage allows client-side javascript to save state on a local machine (if LocalStorage is supported). That is one thing that client-side javascript might use cookies for, but cookies are also used for other things that LocalStorage cannot replace.

For example, LocalStorage is never seen by a server so if a server wants to keep track of some client state itself or track something across multiple pages on a domain, then the server can't use LocalStorage for that and will likely still use cookies. Cookies for a domain are sent to the server with each request on that domain (thus enabling things like authenticated login across all pages in a site). This is something that LocalStorage cannot do.

查看更多
forever°为你锁心
3楼-- · 2019-04-13 01:45

LocalStorage has nothing to do with HTTP; it's a purely client-side feature.

查看更多
登录 后发表回答