4 ms·
Not sure if this is really a good technique. Ecommerce websites often have different places where it's possible to add or remove items and all these places will
by laurent123456 13y ago
Not sure if this is really a good technique. Ecommerce websites often have different places where it's possible to add or remove items and all these places will have to be change to make sure the localstorage is updated. Also there could all kind of special cases that could make the localstorage out of sync. eg. if I add one item, then click back or close the tab before the JavaScript has time to execute. If I close the tab, then login from a different browser, the localstorage will be out of sync too.
There might be ways to solve these issues, but it's definitely more complex than a snippet of JS. Amazon's solution, while requiring an additional HTTP request, is more reliable, and probably more maintainable too.
- SiteKickr 13y agoYou raise good points, no question that this solution will not work for everyone. It would be up to the developer to tailor the this to their needs. For instance, adding an unload event to prevent sync issues. Sometimes improving performance requires a more complex solution, sometimes a less complex solution. It all depends how bad you want to avoid that AJAX call!