使用php新加载页面而不是缓存

Zac*_*ter 1 php browser wordpress caching meta-tags

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

我试过了

<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">
Run Code Online (Sandbox Code Playgroud)

另外,因为这是WordPress,我只是将css排入最后添加主题版本的css.style.css?ver = 2.0.

出于企业的需要,我在IIS上运行它.

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

Joe*_*Joe 6

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

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

你也可以在CSS/JS/etc文件中使用PHP头文件,但是你需要解析CSS和JS作为PHP,它有点乱.

另一种选择是通过htaccess进行设置 - 由http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html提供.

<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>
Run Code Online (Sandbox Code Playgroud)