0

我很少有随机的 php 脚本,其中包含 HTML 代码的各个部分、样式表和图像。但最近我遇到了缓存问题。

我向样式表添加了一个随机版本号以强制它成为一个新样式表。

    <script>document.write('<link rel="stylesheet" href="/css/fonts/rotate.php?dev=' + Math.floor(Math.random() * 100) + '" type="text/css" media="screen" />');</script> 

如何对图像做类似的事情?

<script>
document.write("<IMG SRC=" + "/images/rotate.php" + ">");

</script>

谢谢

4

2 回答 2

5

您可以将以下标头添加到rotate.php

  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
  header("Cache-Control: no-store, no-cache, must-revalidate"); 
  header("Cache-Control: post-check=0, pre-check=0", false); 
  header("Pragma: no-cache"); 

您也可以通过 .htaccess 文件尝试:

<Directory />
    <filesMatch "rotate.(html|htm|js|css|php)$">
    FileETag None
    <ifModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </ifModule>
    </filesMatch>
</Directory>
于 2013-03-08T01:07:12.013 回答
-3

您可以在最后添加随机乱码参数。

"/images/rotate.php?dev=" + Math.floor(Math.random() * 101)
于 2013-03-08T01:04:54.203 回答