Personally, I prefer not to store data in Cookie or even in localStorage, but in the built-in database IndexedDB .
We include a special library that simplifies working with the InxdexedDB base:
Next, to save some data, we execute in the browser console:
result = await localforage.setItem('key', save_data);
console.log('Данные успешно сохранены:');
Where in save_data is the saved data, and key is the key by which you could get access to them.
One of the important features here is that in save_data we can put any data type - even a string, even an array, or an object. You can even save the file if you want! At the same time, there are no restrictions on the amount of stored data, you can shove at least a megabyte or even a hundred megabytes - the built-in storage will gobble up everything.
To later retrieve the saved data, just execute:
result = await localforage.getItem('key');
console.log('Данные успешно извлечены:');
Data storage period is unlimited. Or until the user manually zeroes the browser.Anonymous
Depending on the situation.
If I need to do some preliminary check, then I work on the backend side.
If no checks need to be done, then I add it from the client side.Anonymous
To place the code, please use CodePen or similar tool. Thanks you!