2

I have a specific page in a WordPress site that I want to disable client-side browser caching for.

I found a plugin (https://wordpress.org/plugins/prevent-browser-caching/) but we want to avoid adding unnecessary plugins for maintenance / security reasons.

I also found a way to do this with HTTP headers (How do we control web page caching, across all browsers?) but by the time WordPress is rendering the page, it's too late to manipulate the headers.

I am doing this custom PHP, but it gets stuck in an infinite loop... thoughts?

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();
}
theduck
  • 2,589
  • 13
  • 17
  • 23
John M
  • 39
  • 3

1 Answers1

-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();

}
John M
  • 39
  • 3