1

I've started developing mobile website using jquery mobile. Since I have to carry accross multiple pages some json data I wonder what would be a better approach, storing that json data inside cookie or using html5 local storage. Both approaches would use jquery.

Scenario would be following:

  1. Home controller returns some initial data as json
  2. User selects some from that initial list
  3. User selection should be stored immediatly on local storage
  4. When navigate further on different page those data should be available (retrieving from local storage)
aroth
  • 54,026
  • 20
  • 135
  • 176
user1765862
  • 13,635
  • 28
  • 115
  • 220

2 Answers2

3

Either approach will work. The decision on which to use comes down to a handful of points:

  • Do you need access to the JSON data on the server? If so, it's simpler to use cookies (otherwise you'll have to script the page to manually send the JSON when the server needs it). Or if you rarely/never need the JSON data on the server, you'll save some bandwidth by using local storage.

  • Do you need to store large amounts of data? With cookies you're limited to 4K per cookie. With local storage you have access to 5 MB of space.

  • Are you concerned about supporting older browser versions, or some esoteric/less popular browsers that don't have HTML5 support? Cookies will work with a broader range of browsers than local storage.

Further discussion here: Local Storage vs Cookies

Community
  • 1
  • 1
aroth
  • 54,026
  • 20
  • 135
  • 176
0

localStorage would be better option for your need than cookie.

Cookie send the request to HTTP during every page is loaded.

Suman Bogati
  • 6,289
  • 1
  • 23
  • 34