I’m developing sites and some visitor’s browsers appear with old cache.
Is there a way we can clear visitor’s browser cache using codes from the server side or even javascript so they don’t have to clear themselves?
I cannot find the direct answer to this.
There must be a way big companies do like Facebook, Ebay etc
3
Answers
We have been using htaccess to determine the caching rules of the clients. We explicitly give the cache a 24h lifetime and we put no-cache rules the day before we do the update. It has helped but it is tedious and not so reliable.
Just posting it to give you ideas if no one answers, but I would really love to get the answer too. 🙂
First Method:
You can actually save the output of the page before you end the script, then load the cache at the start of the script.
example code:
You can actually save the output of the page before you end the script, then load the cache at the start of the script.
example code:
If you have a lot of pages needing this caching you can do this:
in cachestart.php:
in cacheend.php:
Then just simply add
include(‘cachestart.php’);
at the start of your scripts. and add
include(‘cacheend.php’);
at the end of your scripts. Remember to have a folder named cache and allow PHP to access it.
Also do remember that if you’re doing a full page cache, your page should not have SESSION specific display (e.g. display members’ bar or what) because they will be cached as well. Look at a framework for specific-caching (variable or part of the page).
Second Method:
Use Squid or update the HTTP headers correctly to do browser caching.
PEAR has a caching package (actually two):
http://pear.php.net/package/Cache
Fourth Method:
Use http://memcached.org/. There’s an explanation of how to do it on that site.
I usually use a combination of techniques:
/public/styles.f782bed8.css
) and remove it again with mod_rewrite. This way every change in the file results in a new file name. This can be done at runtime in PHP while outputting the HTML header, to have it fully automated. In this case however an MD5 might have a performance impact.