【问题标题】:Disable client-side browser caching for specific page禁用特定页面的客户端浏览器缓存
【发布时间】:2019-11-21 04:19:50
【问题描述】:

我想要禁用客户端浏览器缓存的 WordPress 站点中的特定页面。

我找到了一个插件 (https://wordpress.org/plugins/prevent-browser-caching/),但出于维护/安全原因,我们希望避免添加不必要的插件。

我还找到了一种使用 HTTP 标头 (How do we control web page caching, across all browsers?) 执行此操作的方法,但是当 WordPress 呈现页面时,操作标头为时已晚。

我正在做这个自定义 PHP,但它陷入了一个无限循环......想法?

if ($department == "xxxxxxxxxx" && time() - $_GET['nocache'] > 1) {
  echo time() - $_GET['nocache'];
?>

  <html>
  <body>
  <script>
    var curr_page = window.location.href,
    next_page = "";
    next_page = curr_page + "?nocache=" + <?= time()?>;
    window.location = next_page;
  </script>
  </body>
  </html>

  <?php
  die();
}

【问题讨论】:

    标签: php wordpress


    【解决方案1】:
    if ($department == "xxxxx" && time() - $_GET['nocache'] > 900) {
    ?>
    
      <html>
      <body>
      <script>
        var curr_page = window.location.pathname,
        next_page = "";
        next_page = curr_page + "?nocache=" + <?= time() ?>;
        window.location = next_page;
      </script>
      </body>
      </html>
    
      <?php
    
      die();
    
    }
    

    【讨论】:

    • 这是一个答案还是您只是从帖子中复制了代码?
    • 这就是答案。
    猜你喜欢
    • 2010-11-21
    • 2021-02-10
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-30
    • 1970-01-01
    相关资源
    最近更新 更多