I am building a website, and I have about 100 pages with the same information below in the head of the files.
<!--CSS imports-->
<link rel="stylesheet" type="text/css" href="../PrimaryCSS.css">
<link rel="stylesheet" type="text/css" href="../NavigationBarCSS.css">
<link rel="stylesheet" type="text/css" href="../FooterCSS.css">
<!--Bootstrap imports-->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="../bootstrap-3.3.4-dist/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="../bootstrap-3.3.4-dist/css/bootstrap.min.css">
<script src="../bootstrap-3.3.4-dist/js/bootstrap.min.js"></script>
<!--HTML Imports for the footer and navigation bar-->
<script src="../fileLoaderMain.js"></script>
The Problem:
The main issue with this is that if I want to change the bootstrap libraries, I have to go into each file and change the library paths. The other issue is that if I want to add or remove a stylesheet, I have to go into each html file to add or remove it.
The Question:
Is there a way I can put all of this information in one file and then have a line like <script> src="importHead.js" </script>
that imports everything that needs to be in the head of the file?
For example, in the "fileLoaderMain.js" file, I have javascript functions that import the html for the page navigation bar and footer. The functions look like this:
$(function () {
$("#navbarComponentMainPagesID").load("../navbarComponentMainPages.html");
});
$(function () {
$("#footerComponentID").load("../footerMainComponent.html");
});
Then in the HTML file, I call the function which imports the navigation bar and footer like this. The divs look like this:
<div id="navbarComponentMainPagesID"></div>
<div id="footerComponentID"></div>
That way, I only have to make changes to the navigation bar and footer in one file.
What I Tried:
I tried to do something similar using javascript functions to solve my current problem, but it didn't work. I put all of the imports (stylesheets and libraries) into a file. Wrote a javascript function to import them and added a div to show where the files should be imported in the main HTML file. But that didn't work, and I'm guessing that's because you can't import javascript and jquery files using divs.
I feel like this is probably a simple problem, but I haven't done a lot of complex things with web development.