Reputation: 9
Is there any manner in which you would be able to set a cookie for a browser client side but not have it relayed with every POST/GET request?
Upvotes: 0
Views: 28
Reputation: 707218
Is there any manner in which you would be able to set a cookie for a browser client side but not have it relayed with every POST/GET request?
No, there are not cookies that are client-side only. There is the reverse - cookies that are only server accessible.
If you don't want a server to see the data, then you must use something other than a cookie that is stored in the browser such as LocalStorage. The storage is still domain specific, but is only available to the Javascript in the page and is not sent to the server.
You can read about both LocalStorage and SessionStorage here on MDN.
// store a string in localStorage
localStorage.setItem("myKey", str);
// retrieve a string from localStorage
var str = localStorage.getItem("myKey");
Upvotes: 2
Reputation: 318488
Yes, use localStorage
or sessionStorage
. Both provide the ability to store data that is only available client-side. Assuming you want persistence beyond tabs, localStorage
is the way to go.
Upvotes: 2