Reputation: 1065
A very simple question, I need time when a file was cached on client's computer.
I want to reload page from server if it's modified after the time of cached file.
Is it possible? I'm completely unaware about this. Any help will be appreciated.
Upvotes: 0
Views: 41
Reputation: 20469
You could embed a timestamp into the html somewhere:
<body data-generated="<?php echo time();?>">
Then check this against server updated time, via an ajax request:
//jquery for berevity
$.get('invalidate_client_cache.php?time='+ $('body').data('generated'), function(data){
if(data.invalidate){
location.reload(true);
}
}
I will leave the php implenentation to you, as i dont know yout requirements, but it could be something like:
$clientCacheTime = isset($_GET['time'])? $_GET['time'] : null;
$data=[];
$data['invalidate'] = reloadRequired($clientCacheTime);
header('Content-Type: application/json');
echo json_encode($data);
Upvotes: 1