E-CommerceWebsite
E-CommerceWebsite copied to clipboard
Violating DRY Principles (Repeated Load Function)
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>