-1

The problem is simple to explain. If I visit a page of the website, then I login and after I come back to that page, I see that page like I wasn't logged in. If I refresh the page, then the correct version is loaded.

I know that probably this is a question asked many times... But I'm trying to find a solution since days and nothing work; I also read a lot of other threads.

One of my last attempts was this PHP code:

if ( is_user_logged_in() ) :
    header('Expires: Sun, 01 Jan 2014 00: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');
endif;

And this HTML:

<?php if ( is_user_logged_in() ) :
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="expires" CONTENT="0">
<?php endig; ?>

I'm using the plugin Autoptimize for caching, but it's the same problem even if is I disable it.

To conclude, my goal would be avoid logged in users to see cache pages.

Any help or tip would be immensely appreciate (if you want to have a look I can give you the website link).

Thanks

UPDATE:

 header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
 header("Pragma: no-cache"); //HTTP 1.0
 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
9
  • 1
    not sure how is this related to wordpress. you should probably spend time understanding how browser caching works before setting caching directives. Aug 4 at 9:22
  • 1
    also the browser won't load the page that you're setting the directives on if it's pulling from cache, I'd agree with Mark though, your current approach of sending things if the user is logged in is unlikely to solve your problem, and adding random directives may harm your site if you're not careful
    – Tom J Nowell
    Aug 4 at 9:40
  • That was actually a stupid test I did, already knowing that would have never worked. And I tried to understand how browser cache works, but anyway I can't find a solution.
    – supadema
    Aug 4 at 9:54
  • the solution is not to cache, but not sure how happy you going to be with this Aug 4 at 10:12
  • 1
    as said in the first comment, this has nothing to do with wordpress and probably would have been better asked at SO. As for performance of the website, well browser caching is not useful IMHO for HTML and wordpress by default should send the appropriate headers for browsers to not cache the HTML. If your pages are being cached there is probably some plugin or server setting that is responsible for that. That said, if the requirement is to do browser caching for HTML for not logged in user, than that is the requirement and it usually more important than performance Aug 4 at 15:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.