Currently, I am utilizing the library js-cookie instead of my previous use of jquery.cookie
.
I have encountered an issue related to duplicating cookie entries.
There are occasions when I invoke the following method:
Cookies.set('my-cookie-name', 'value', {'path': '/'});
Although I am certain that this method is only called once in my code base, I sometimes end up with:
---------------------------------------------------------------
Name Value Domain Path
---------------------------------------------------------------
my-cookie-name 1 mydomain.com /foo/bar/
my-cookie-name value mydomain.com /
---------------------------------------------------------------
This inconsistency does not manifest consistently. Since this problem occurs infrequently, it is challenging to pinpoint. As a temporary solution, I remove the cookie before setting a new value and temporarily avoid encountering the issue again. However, I believe this approach is flawed.
The cookie named 'my-cookie-name'
is specifically set in one section of the code.
This discrepancy was identified on my development machine, ruling out the possibility of stale cookies being responsible.
I utilize cookies to toggle a state, as demonstrated by the following snippet:
var state = 'on';
$elem.on('click', function(e){
state = state === 'on' ? 'off' : 'on';
Cookies.set('my-cookie-name', state, {path: '/'});
});
Could this usage be incorrect? Should I consider removing old cookies before setting new values?
Browser: Chrome v45