Forum Moderators: phranque
<header>
________
| <nav> |
|_______|
<main>
| | |
| <section> | <aside> |
| | |
|__________|_______|
<footer> // Change all internal links to
<a href="$link" onClick="loadPage('$link'); return false">Internal Link</a> // not tested, just written for this post
function loadPage(url) {
$('main').html('Loading...');
$('main').load(url + ' main', function(response, status, xhr) {
if (status != 'error') {
var thisTitle = $(response).filter('title').text();
history.pushState({url: url}, thisTitle, url);
document.title = thisTitle;
}
});
} You should not be reloading the JS, CSS on every load anyway
Since it's ajax, does everything behave as intended if the visitor has scripting turned off?
<?php
include 'header.php';
echo <<<EOF
<main>
...
</main>
EOF;
include 'footer.php';
?> 4 seconds seems an awfully long time just to load up a kilobyte or two of content.
loadPage(url) would use Ajax to just load that <main>...</main> section; essentially skipping the two included pages. In theory, non-JS browsers would still load the included pages, and if the user returned via a bookmark or search engine then it would load the included pages, too
$('main').load(url + '?includes=1 main', function(response, status, xhr) {...} <?php
if (!$_GET['includes'])
include 'header.php';
...
?>
You should not be reloading the JS, CSS on every load anyway, it should all be cached.