0

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.

Guy in the chair
  • 1,045
  • 1
  • 13
  • 42
  • 2
    Two common ways are to send `Cache-Control` headers, or include client-side files (like js or css files) with a revision number (` – Elias Van Ootegem Nov 12 '14 at 12:20
  • possible duplicate of [How can I force clients to refresh JavaScript files?](http://stackoverflow.com/questions/32414/how-can-i-force-clients-to-refresh-javascript-files) – Elias Van Ootegem Nov 12 '14 at 12:21

1 Answers1

1

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);
Steve
  • 20,703
  • 5
  • 41
  • 67