E-CommerceWebsite icon indicating copy to clipboard operation
E-CommerceWebsite copied to clipboard

Violating DRY Principles (Repeated Load Function)

Open codeCraft-Ritik opened this issue 10 months ago • 0 comments

Description: The index.html file defines the same load(url) function four separate times to import the header, slider, content, and footer. This makes the code redundant and harder to maintain.

Current Code (index.html) - Improved Code:

<script>
    function loadSection(id, url) {
        const req = new XMLHttpRequest();
        req.open("GET", url, false); // Consider changing to true for async
        req.send(null);
        document.getElementById(id).innerHTML = req.responseText;
    }
    loadSection("1", "header.html");
    loadSection("2", "slider.html");
    loadSection("3", "content.html");
    loadSection("4", "footer.html");
</script>

codeCraft-Ritik avatar Jan 25 '26 08:01 codeCraft-Ritik