Skip to content

Violating DRY Principles (Repeated Load Function) #30

@codeCraft-Ritik

Description

@codeCraft-Ritik

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>

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