Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put HTML head in another file

Is there a way to include all the meta tag, link rel and script src includes in one file, and then require that file?

The reason I ask is because I have like 10-15 lines that i am copying into every file and figured there might be another way.

I put everything in one file and tried the Jquery load function, but to no avail.

Thanks

like image 371
NorCalKnockOut Avatar asked Oct 28 '14 21:10

NorCalKnockOut


1 Answers

Create a head.html file like this:

<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<!-- JS -->
<script type="text/javascript" src="js/lib/jquery-1.11.min.js" ></script>
<script type="text/javascript" src="js/lib/angular.min.js"></script>
<title>Your application</title>

Now include head.html in your HTML pages like this:

<head>
   <script type="text/javascript" src="js/lib/jquery-1.11.1.min.js" ></script>
   <script>
       $(function(){ $("head").load("head.html") });
   </script>
</head>
like image 152
benscabbia Avatar answered Sep 24 '22 00:09

benscabbia