You will need to create an html file that will house the links you want to keep introducing in subsequent pages such as a head.html file for example, then inside it place the links and other content you deem necessary to be in the head, for example I can place the charset and viewport meta tags and the CDN link for Bootstrap.
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
Then in your subsequent pages that you want to include these links in their respective head elements, you can place a script tag within their head tags or at the end of your content within the body tags with this code:
document.addEventListener('DOMContentLoaded', async () => {
try {
const response = await fetch("head.html");
const headContent = await fetch("head.html").text();
const headElement = document.querySelector("head");
headElement.insertAdjacentHTML("afterbegin", headContent);
}
catch(error) {
console.log("Error fetching head.html", error);
}
});
You can also put the code within its own JavaScript file then link that file within the pages you need if you want to avoid having the code plainly written within your HTML file.
Now every page that uses this will contain the