简体   繁体   English

缓存问题(看到完全不同的网站版本)

[英]Caching Issues (Seeing entirely different versions of the website)

If a page or even just a word on a page gets updated I won't see the changes until physically pressing the refresh button on the browser.如果页面甚至页面上的一个词被更新,我将不会看到更改,直到物理按下浏览器上的刷新按钮。 Sometimes I'll even see versions that haven't existed for days.有时我什至会看到好几天都不存在的版本。 Note this isn't a SHIFT-F5 or a cache reset, it's literally just pressing the refresh button, f5 or on mobile swiping down to refresh the page.请注意,这不是 SHIFT-F5 或缓存重置,它实际上只是按下刷新按钮、f5 或在移动设备上向下滑动以刷新页面。

I redirect all traffic to a routing index.php for basic mvc layout.我将所有流量重定向到路由 index.php 以进行基本 mvc 布局。

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [QSA,L]

There is no PHP Opcache, there is nothing.没有 PHP Opcache,什么都没有。

I have put this into .htaccess to make sure there is no caching.我已将其放入 .htaccess 以确保没有缓存。

<filesMatch "\.(html|htm)$">
  FileETag None
  <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</filesMatch>

Going to a different computer in the house, the site will again, show the old version until you press refresh on the browser.转到家中的另一台计算机,该站点将再次显示旧版本,直到您在浏览器上按刷新。 It's driving me crazy and I have no idea whats going on.这让我发疯,我不知道发生了什么。

Note: This is a shared hostgator server.注意:这是一个共享的 hostgator 服务器。

If you have cache problem with php file,you can use below code.如果你的 php 文件有缓存问题,你可以使用下面的代码。 It will remove your file from cache.它将从缓存中删除您的文件。

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

If you are facing problem with any single css/js files, you can append the current date at end of url.如果您遇到任何单个 css/js 文件的问题,您可以在 url 末尾附加当前日期。 So every time it loads from server not from cache所以每次从服务器加载而不是从缓存加载

Example:
https://somewebiste.com/css/abcd.css?date=<?=date('ymdhis');?>
https://somewebiste.com/css/abcd.js?date=<?=date('ymdhis');?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM