加载页面新鲜,而不是从缓存与php


Load a page freshly and not from the cache with php

我刚刚将我的站点的开发版本移植到生产中,它仍然显示旧图像并使用旧样式表。这是发生在每个人身上的。

我试着

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Pragma-directive" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Directive" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="0">

另外,因为这是WordPress,我只是在最后添加主题版本的css。所以style.css ?版本= 2.0。

出于公司需要,我在IIS上运行这个。

这些选项似乎都不能正常工作。当用户访问网站时,我如何加载新页面而不是从缓存加载?

假设您在PHP页面中,只需将一个随机数附加到请求

<link rel="stylesheet" type="text/css" href="style.css?random=<?php echo rand(1,100000); ?>" />

你也可以在CSS/JS/etc文件中使用PHP头文件,但是你需要将CSS和JS解析为PHP,这会变得有点混乱。

另一个选项是通过http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html

提供的htaccess设置它。
<FilesMatch "'.(html|htm|js|css)$">
    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>

因为这是WordPress:

尝试Style.css最后版本的WordPress插件,它防止CSS缓存像一个魅力。https://wordpress.org/plugins/stylecss-load-last-version/

欢呼,