2017-09-22 23:52
浏览 173


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.

图片转代码服务由CSDN问答提供 功能建议

我目前正在开发一个WordPress驱动的电子商务网站,其中选择的购物平台是WooCommerce。 \ n

有没有办法,不使用插件,这将允许我阻止浏览器缓存某些PHP文件? 在这个例子中,'header.php'和'cart.php'文件? 我的假设是,需要修补'.htacess'文件,但后来我可能错了。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongren4099 2017-11-15 16:17

    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.

    <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"

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

    点赞 打赏 评论
  • dongwu5743 2017-09-22 23:56

    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");
    点赞 打赏 评论

相关推荐 更多相似问题