0

Had a problem with the dynamic site (100% ajax) not updating when it goes to different pages. I just want to cache the html pages. The css and js is unchanging, I WANT that to cache you know?

I added the following php

Response::header('Cache-Control', 'no-store, private, no-cache, must-revalidate'); // HTTP/1.1
Response::header('Cache-Control', 'pre-check=0, post-check=0, max-age=0, max-stale = 0', false); // HTTP/1.1
Response::header('Pragma', ' public');
Response::header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT');                  // Date in the past  
Response::header('Expires', '0', false); 
Response::header('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
Response::header('Pragma', 'no-cache');

and the following html

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

will it disrupt the css/js or JUST make the html have to reload.

1
  • 1
    One way is to append ?t=<?php echo time(); ?> to script and CSS URLs. This will disable caching 100%. Commented Sep 28, 2013 at 8:45

1 Answer 1

1

"I just want to cache the html pages" in your question is a bit confusing. From what I gather your problem is that the browser caches the content but you want to DISABLE the caching. :)

Anyways:

Whatever you add in your PHP output only affects your PHP output. If you produce HTML in your PHP scripts, then only the HTML produced by PHP is affected, nothing else.

Bonus answer:

Should you wish to change the caching policies for .js and .css files, then you need to manhandle Apache's httpd.conf or .htaccess (assuming Apache is your HTTP server)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.