Is using localStorage for a guest shopping cart a bad idea?

2021-10-14

localStorage Shopping Cart

I've found myself building some custom, basic e-commerce sites these days in Rails. I have a few options when it comes to building out a basic guest user shopping cart. These sites will not have logged in users so it is not necessary to tie the cart to a user account in any way. This has led me to consider using the localStorage api to persist the cart. The other option is to go with the tried and true store the cart in a database temporarily and tie this to the user via cookie in the browser.

In terms of browser support, localStorage sports browser support of IE8 and up. This is more than sufficient. In terms of speed and simplicity to develop, I believe that localStorage also has the win here.

While a database is more secure, in this case it's just storing an array of products to be later turned into an order. This order content is going to be sanitized by the server so that isn't a huge strike against localStorage either.

So I pose the question to the community, what are the drawbacks of using a localStorage shopping cart for this scenario? Has anyone done this only to regret it later?

localstorage