I have 3 files: index.html, header.js and footer.js.
I wonder if I can use just one JS script to read line by line the HTML files header.html and footer.html (files instead of header.js and footer.js) and return for each line of the file the document.write('line content');?
Instead of having header.js and footer.js I want to have header.html and footer.html and one JS file for transforming the HTML into JS file: header.html transformed into header.js.
index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<script type="text/javascript" src="header.js"></script>
<!-- CONTENT -->
<div id="content">
<h1>Title</h1>
<h2>Substitle</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<!-- END OF CONTENT -->
<script type="text/javascript" src="footer.js"></script>
</body>
</html>
header.js
document.write('<!-- HEADER -->');
document.write('<div id="header">HEADER</div>');
document.write('<!-- END OF HEADER -->');
footer.js
document.write('<!-- FOOTER -->');
document.write('<div id="footer">FOOTER</div>');
document.write('<!-- END OF FOOTER -->');
At the end the index.html will look like this:
index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<script type="text/javascript" src="include.js?file=header.html"></script>
<!-- CONTENT -->
<div id="content">
<h1>Title</h1>
<h2>Substitle</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<!-- END OF CONTENT -->
<script type="text/javascript" src="include.js?file=footer.html"></script>
</body>
</html>
The rest of the files will look like this:
header.html
<!-- HEADER -->
<div id="header">HEADER</div>
<!-- END OF HEADER -->
footer.html
<!-- FOOTER -->
<div id="footer">FOOTER</div>
<!-- END OF FOOTER -->