Support » Fixing WordPress » Force page reload on every visit

  • Resolved Andreas

    (@andreaskarsten)


    Hi there,

    is there a possibility with WordPress to force a reload every time someone visits the page? In other words: Can I make sure that each visitor sees the latest version of the site?

    At the moment, it depends on the visitors settings and whether or not they remember to hit the reload button or press F5 if they have been to the site before. I would like that to change.

    Thanks for any tips, suggestions and hints.

    Andreas of Nonformality

Viewing 6 replies - 1 through 6 (of 6 total)
  • jetshack

    (@jetshack)

    For static sites, if the content of your site has changed then the visitor should see the latest content. I THINK their browser will compare the cached doc time stamp vs the time stamp on the file on the server, if they’re the same then it loads the cached doc otherwise it grabs the newer version off the server.

    For WordPress sites the index.php is being generated dynamically so it will always load from the server…

    To reload a page at a set in terval add this to the head

    <META HTTP-EQUIV="refresh" CONTENT="XX">

    change XX to the number of seconds you want to to wait between refreshes… Don’t know how that would be of benifit to most sites (maybe stock tracking)…

    Or you could put a link on the page telling them to refresh it at their leisure with something like this

    <A HREF="javascript:history.go(0)">Refresh</A>

    or you could do it with a button….

    <FORM>
    <INPUT TYPE="button" onClick="history.go(0)" VALUE="Refresh">
    </FORM>

    Thread Starter Andreas

    (@andreaskarsten)

    Thank you jetshack.

    The problem is of course when users have the option in to never update a webpage allowing for faster web page viewing but preventing a fresh page.

    Other possibilities I have discovered meanwhile, next to the refresh metatag, are these:

    <META HTTP-EQUIV=”Pragma” CONTENT=”no-cache”>
    <META HTTP-EQUIV=”Expires” CONTENT=”-1″>

    Also see this Microsoft Knowledge Base Article. I am not so sure about the suggestion to add another header section at the end of a document…

    And I am not quite sure which of these tags has which effect on which browser.

    Clarification would be appreciated – if clarity exists. And I will try out putting these things in my header soon.

    jetshack

    (@jetshack)

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    A better way to prevent caching:

    Throw this into your theme’s header.php, at the top, above everything else (including the doctype):

    <?php
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    ?>

    That will usually do it. Pragma tags don’t always work for this sort of thing. They rarely affect proxy systems, for example. But nearly everything obeys real HTTP headers.

    Thread Starter Andreas

    (@andreaskarsten)

    Thank you guys. That should do it!

    I inserted this code into my header.php file (above everything else):

    <?php
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: post-check=0, pre-check=0', FALSE);
    header('Pragma: no-cache');
    ?>

    It seems to do the trick.

    See more information here:

    The PHP Anthology Volume 2, Chapter 5 – Caching

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Force page reload on every visit’ is closed to new replies.