PHP 如果在根文件夹中修改和更新数据,即使在页面刷新后也不会在 Web 视图中显示更新的数据

PHP is not displaying updated data in the the web view even after the page refresh if data is modified and updated in root folder

新 PHP!

所以我在本地 xampp 服务器中部署了 PHP 应用程序,并且在根 folder/JSON/.

中有一个 .json 文件

在 javascript 中,我有一个每 10 秒运行一次的循环。它获取本地存储的 json 文件和图像并显示在网络视图上。如果本地存储 json 数据或更新同名新图像,Web 视图在 10 秒后不会反映更改,即使刷新网页,更改也不会反映在网页中。

可能是什么原因。如何让它发挥作用。

<script>
    for(let i=0; i<n; i++){
        var nextPage = setTimeout(function() {
            fetch('json/imagePathsMappingToCodes.json') //Locally stored JSON
            .then(resp => resp.json())
            .then((imagePath) => {
                console.log(imagePath); //Does not reflecting changes when json is modified in the mean time to 
            }
        }, i* 10000)
    }
</script>

这可能是由于浏览器缓存。如果您在浏览器中进行硬刷新或以隐身模式打开页面,会发生什么情况?

要解决此问题,有几种解决方案:

  • 强制浏览器再次下载资源(快速且肮脏):您可以在服务器的 .htacces 中禁用缓存 根据您网站的使用情况,这可能是一个非常糟糕的主意,因为它会迫使您的用户一次又一次地下载(可能的)相同图像。
  • 每次上传新版本时更改资源的文件名。