问题
Aware of issues like:
- Cookies are included with every HTTP request, thereby slowing down your web application by needlessly transmitting the same data over and over
- Cookies are included with every HTTP request, thereby sending data unencrypted over the internet (unless your entire web application is served over SSL)
- Cookies are limited to about 4 KB of data — enough to slow down your application (see above), but not enough to be terribly useful
(from: http://diveintohtml5.info/storage.html)
I decided to use localstorage instead of cookies.
QUESTION: Can I limit localstorage context to certain path like with cookies?
回答1:
As mentioned in the comments already, webstorages (localStorage
, sessionStorage
) are scoped per origin.
User agents must have a set of local storage areas, one for each origin.
Source: http://www.w3.org/TR/webstorage/#the-localstorage-attribute
What is an origin?
Let's just quote the w3.org wiki page on the same origin policy:
An origin is defined by the scheme, host, and port of a URL.
Source: http://www.w3.org/Security/wiki/Same_Origin_Policy
回答2:
Use some fresh Library!
https://www.npmjs.com/package/pathstorage
I was agony for the same subject. And I choose solution "made my own". :)
来源:https://stackoverflow.com/questions/25013643/is-it-possible-to-use-localstorage-with-context-per-path-like-cookie