Help me analyze this. I have a cart that can be use anonymously. That mean I need some sort of storage to store it in client side. I didn't know better between the two options. The localStorage seem good for having a bigger size but cookie send to server with every request which is good and easier to working with authentication to detect the client cart and the cart that auth user currently had.
Personally I wouldn't choose between both. Just keep track of an anonymous cart in your database.
You probably already have some cart in your webshop. You only need to make it possible to link it to a session id (or a key that you store in a cookie) instead of an actual user. This way you only need to develop it once. And an anonymous user can be a logged in user 5 seconds later. It is a breeze to link the cart to the logged in user. If you keep track of products somewhere else than the cart itself you need to sync them.... and that is extra work and room for errors.
@click Can you explain on what you said ". You only need to make it possible to link it to a session id (or a key that you store in a cookie) instead of an actual user"?
@Cronix My cart is vue component and I decide to use localStorage. Look like a lot of more works to get it done right. Currently, I want the login user to get the cart from the client. I don't know how to do that with localStorage yet. Maybe send it through hidden input in login form but I'm not sure.
I don't know about session storage. Maybe I should take a look now.
@click safari *kinda has problem with everything. Some open source has a fall back to cookie if local storage not supported. That's a lot of work. Not saying that's hard but time consuming.