I am currently in the process of creating a website that consists of approximately 100 pages. Each page contains similar code within the head section of the HTML 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 footer and navigation bar-->
<script src="../fileLoaderMain.js"></script>
The Challenge:
One major issue I face is the need to manually update each file if I want to modify the bootstrap libraries or add/remove stylesheets. This process becomes repetitive and time-consuming.
The Inquiry:
I am seeking a solution that allows me to consolidate this repeated information into one file, which can be referenced by a single line like
<script> src="importHead.js" </script>
to automatically include all necessary components in the head section.
For instance, within the "fileLoaderMain.js" file, I have created functions in JavaScript to import the HTML elements for the navigation bar and footer. These functions appear as follows:
$(function () {
$("#navbarComponentMainPagesID").load("../navbarComponentMainPages.html");
});
$(function () {
$("#footerComponentID").load("../footerMainComponent.html");
});
In the HTML file, I can simply call these functions to import the navigation bar and footer by including corresponding divs like so:
<div id="navbarComponentMainPagesID"></div>
<div id="footerComponentID"></div>
This method enables me to make any changes to the navigation bar or footer in just one location.
Previous Attempts:
My initial approach involved using JavaScript functions to address the current issues encountered. However, my attempt failed when trying to import all necessary resources (stylesheets and libraries) via a single call in the main HTML file. I suspect that it was unsuccessful because importing JavaScript and jQuery files through div tags may not be supported.
While I believe this could be a relatively straightforward problem to solve, my experience with complex web development tasks is limited.