My PHP-based site files start off with
<?php include("PHP/header.php"); ?>
which includes all the HTML (metadata, scripts, etc.) shared by every page - along <head>
and <title>
. The options I've considered for dynamic page titles are:
<title id="title">...</title>
...
<script>window.onload=function(){document.getElementById('title').innerHTML="New title"}
</script>
and
<?php include("PHP/header1.php"); ?> <!-- code in header.php before <title> -->
<title>New title</title>
<?php include("PHP/header2.php"); ?> <!-- code after </title> -->
(I intend the same for page descriptions - omitted for brevity.)
Which of these is preferable for search engine optimization - do better approaches exist? Lastly, any performance differences to note (scripts vs. php, etc)?