Is there a meta tag or something I can use that tells the browser to not use a cache from before a certain date.
e.g.
<meta "only use cache if cache is AFTER 4/4/2013">
If the cache is old it needs to download all the new Javascript, CSS, Images, etc..
I make a lot of updates to the site and then it screws up anyone who still has a cache (and you can't expect them to know to press ctrl+f5 or ctrl+r).
I usually just add a get parameter on the end with the version of the script I am presenting them
so if you have your javascript at
www.example.com/script.js
use the url
www.example.com/script.js?foo=1
when I increment the value of foo everytime, this forces the browser to refetch the script.
There is not a meta tag for setting cache only after a certain date but if you are using any server language (PHP, .NET, ruby, phyton) you can set cache-control to no-cache and then dynamically set the headers to start caching after a certain date.
For example using PHP:
<?php
$cdate = date('Ymd');
if ($date > '20130404') {
header('Cache-Control: max-age=28800'); //cache lifetime to 8 hours
} else {
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With