i have a php based website which.
I use a switch case to include different pages and navigate.
i have employed a method so that my index page includes a navigation bar and a footer
my problem is that each time i navigate from one page to another everything is loaded again and makes the website heavy.
<?php include('models/header.php'); ?>
<div id="content">
<center>
<div id="switch" align="center">
<?php
switch($view)
{
case 'Index':
include('pages/index.php');
break;
case 'Services':
include('pages/Services.php');
break;
case 'About':
include('pages/about.php');
break;
case 'Contact':
include('pages/contact.php');
break;
case 'Download':
include('pages/download.php');
break;
default:
include('pages/error.php');
}
?>
</div>
</div>
</center>
<br>
<?php include('models/footer.php'); ?>
</div>
is there a way i can set it u so that these elements get preloaded once and stay in the cache so that they dont need to be loaded everytime i navigate to a new page…?
Given your code, you actually don’t need to cache anything, doing so could lead to more overhead that it is actually needed.
Cached or not cached, you will still need to access a file, which your gain will be the opcode generation. But PHP still needs to access filesystem, except if you use a memcached solution with RAMFS, you won’t note a real change.
However, you really need to cache your code, for obvious reasons, you should take a look at APC, which is an opcode cache for PHP.
Basically, it’ll cache the calls you make to your included file and cache the PHP interpreter result.
Finally, I actually advise you to give a read to Best Practices for Speeding Up Your Web Site which will help you enhance user experience in a probably more notable way.