6

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?

andilabs
  • 22,159
  • 14
  • 114
  • 151
  • 3
    Storage is per origin. But it's standard to namespace your variables : `localStorage['moduleA.a']` which helps manage big sites (or origins with many different sites). – Denys Séguret Jul 29 '14 at 10:57
  • I found some info here: http://stackoverflow.com/questions/9742395/scope-of-sessionstorage-and-localstorage – andilabs Jul 29 '14 at 10:58
  • I would not care on 4Kb of transmitting data in year 2014. Each of those has [diff purposes](http://stackoverflow.com/questions/3220660/local-storage-vs-cookies) – fed.pavlo Jul 29 '14 at 10:58

2 Answers2

8

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

David Mulder
  • 26,123
  • 9
  • 51
  • 114
0

Use some fresh Library!

https://www.npmjs.com/package/pathstorage

I was agony for the same subject. And I choose solution "made my own". :)

HansolLim
  • 61
  • 5