fix: css/js loader

This commit is contained in:
dhanush.s 2025-09-24 14:28:52 +05:30
parent e2290b1ede
commit eda7a7c463

View File

@ -5,7 +5,37 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kodepilot Clone</title>
<link rel="stylesheet" href="main.css">
<script>
async function loadAsset(primary, fallback, type) {
try {
const res = await fetch(primary, { method: "HEAD" });
if (res.ok) {
addTag(primary, type);
} else {
throw new Error("Primary missing");
}
} catch (e) {
addTag(fallback, type);
}
}
function addTag(url, type) {
if (type === "js") {
const s = document.createElement("script");
s.src = url;
s.defer = true;
document.head.appendChild(s);
} else if (type === "css") {
const l = document.createElement("link");
l.rel = "stylesheet";
l.href = url;
document.head.appendChild(l);
}
}
loadAsset("main.css", "https://kodepilot.in/templateapi/main.css", "css");
loadAsset("main.js", "https://kodepilot.in/templateapi/main.js", "js");
</script>
</head>
<body>
@ -417,7 +447,6 @@
</div>
</div>
</footer>
<script src="main.js"> </script>
</body>
</html>