1

I am currently working on a WordPress powered ecommerce website, where the chosen shopping platform is WooCommerce.

Is there a way, without using a Plugin, which will allow me to prevent browsers from Caching certain php files? In this instance, the 'header.php' and 'cart.php' files? My assumption would be, that some tinkering to the '.htacess' file would be required but then I could be wrong.

2
  • What is the actual issue you're trying to solve? Commented Sep 23, 2017 at 0:01
  • The Contents of the Cart are being cached by the browser. Consequently, preventing potential customers from removing products from their basket. Commented Sep 23, 2017 at 0:02

2 Answers 2

2

Not familiar with woocommerce, but generally you should just be able to add the following to the php files:

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. I tried your suggestion, as displayed, but to no success. Should your suggestion be inside any specific tags? I tried placing within <?php [Code Here] ?> but still to no success.
1

I found out the issue. I completely overlooked/forgot, I had the below Caching Code in the .htaccess file. School Boy error!

Once I removed the below code, the Basket Caching Problem was resolved.

## EXPIRES CACHING ## <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType text/css "access plus 1 month" ExpiresByType application/pdf "access plus 1 month" ExpiresByType text/x-javascript "access plus 1 month" ExpiresByType application/x-shockwave-flash "access plus 1 month" ExpiresByType image/x-icon "access plus 1 year" ExpiresDefault "access plus 2 days" </IfModule> ## EXPIRES CACHING ## 

Should I discover a way to cache a website, without the Basket being Cached, I will add it to this answer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.