0

I'm building a simple web app to display Uni. restaurant menus. I need to store user settings without asking anyone to give me any information (ie. login, account name or so). So the whole thing has to be saved at the client-side. The preferences are simple (vegetarian=true, restaurant1=true etc.) so a cookie should do in my opinion.

I'm just a bit confused about JS and cookies. Do they work always? Another discussion on this matter had a comment that modern browsers implement cookies in a way that they won't be retrievable by the website through JS. Is that true? Can I trust JS to save the cookies and retrieve them later on or not?

If JS doesn't work everywhere, how should I handle the user preferences saving/retrieving transparently to the user?

The website portion of my app is HTML5 using Bootstrap, generated by Ractive.js, and menu info fetched and served from JSON files.

pate
  • 4,937
  • 1
  • 19
  • 25
  • As long as you are on the same domain that set the cookies and the user has javascript enabled you will be able to read the user preference cookies from javascript – Jonathan Crowe Jul 04 '15 at 06:42
  • They work everywhere, as long as the user doesn't delete them. – adeneo Jul 04 '15 at 06:42

1 Answers1

0

I'm just a bit confused about JS and cookies. Do they work always?

Yes JS and cookies is always work, and most of the web browser come with it enabled.However, if the user disable it in the browser it will definitely won't work or delete the cookies manually(don't think there is a way to prevent user to do this.) but there is always a way to deal with javascript and cookies disable user check this out How to detect that JavaScript and/or Cookies are disabled?

another discussion on this matter had a comment that modern browsers implement cookies in a way that they won't be retrievable by the website through JS. Is that true?

please have a look on this to have some basic views on javascript cookies. http://www.w3schools.com/js/js_cookies.asp

Can I trust JS to save the cookies and retrieve them later on or not?

yes you definitely can

Community
  • 1
  • 1
John Lim
  • 3,019
  • 4
  • 31
  • 41