Skip to content

Limited Cart Storage (Cookie-Based) #31

@codeCraft-Ritik

Description

@codeCraft-Ritik

Description:

The cart is managed by string-parsing a single cookie. Cookies have a 4KB limit and are sent with every HTTP request, which is inefficient for storing large amounts of data like a shopping cart.

Improved Code: - contentDetails.js

buttonTag.onclick = function() {
    let cart = localStorage.getItem("cart") ? JSON.parse(localStorage.getItem("cart")) : [];
    cart.push(id);
    localStorage.setItem("cart", JSON.stringify(cart));
    document.getElementById("badge").innerHTML = cart.length;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions