无论如何,我可以获取缓存文件的时间


Is there anyway I can get the time of cached file?

一个非常简单的问题,我需要时间在客户端计算机上缓存文件。

如果页面在

缓存文件后被修改,我想从服务器重新加载页面。

可能吗?我完全不知道这一点。任何帮助将不胜感激。

您可以在 html 的某个地方嵌入时间戳:

<body data-generated="<?php echo time();?>">

然后通过 ajax 请求根据服务器更新时间进行检查:

//jquery for berevity
$.get('invalidate_client_cache.php?time='+ $('body').data('generated'), function(data){
    if(data.invalidate){
        location.reload(true);
    }
}

我将把 php 的宽大处理留给你,因为我不知道你的要求,但它可能是这样的:

$clientCacheTime = isset($_GET['time'])? $_GET['time'] : null;
$data=[];
$data['invalidate'] = reloadRequired($clientCacheTime);
header('Content-Type: application/json');
echo json_encode($data);