3

I want to store some non confidential data on the user's browser (or any device/mobile browser) for the next session. I can store that on the cookies but I dont want to send that cookie on any requests to server.

I just need to store and retrieve about 5 key-value pairs, client side only. Is cookie a good fit for this purpose or should I consider local storage? Cross-browser support is very important.

Rob W
  • 341,306
  • 83
  • 791
  • 678
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294

4 Answers4

3

localStorage is supported pretty well.
AmplifyJS provides non-cookie fallbacks for other browsers, with cookies being the last resort.

Rob W
  • 341,306
  • 83
  • 791
  • 678
1

Cookies will be sent on every request to the server (assuming the host & path match).

If you just want a certain page, you can restrict the cookies to a path - take a look at this question.

But I'd go with local storage first.

Community
  • 1
  • 1
chris
  • 36,094
  • 53
  • 157
  • 237
1

LocalStorage is the way to go. Just have a look at this great presentation.

Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
0

Cookies are pre-ajax and were originally implemented to always be sent along in server requests. I would go with local storage with cookies as a fallback for older browsers if you're actually supporting them. People still using IE7 and below aren't exactly performance hounds anyway. If the issue is more about costs on your back end, I would suggest polling to get an idea of how many users will likely actually be relying on the cookie fallbacks. The costs may not actually be significant. IE6 usage is pretty much irrelevant and IE7 is marginalized to the point where people are dropping support for that too. But mostly I would fight like a rabid dog to avoid graceful degradation support for browsers that are over five years old. It solves a lot of problems outright and opens a lot of new doors.

Erik Reppen
  • 4,605
  • 1
  • 22
  • 26