apache 有没有办法禁用单个页面的浏览器缓存?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1479359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to disable browser cache for a single page?
提问by Nathan Long
For a small intranet site, I have a dynamic (includes AJAX) page that is being cached incorrectly by Firefox. Is there a way to disable browser caching for a single page?
对于小型 Intranet 站点,我有一个动态(包括 AJAX)页面被 Firefox 错误缓存。有没有办法禁用单个页面的浏览器缓存?
Here's the setup I'm using:
这是我正在使用的设置:
- Apache under XAMPP, running on a Windows server
- PHP
- XAMPP下的Apache,运行在Windows服务器上
- PHP
Clarification
澄清
The content that I'm primarily concerned about is page text and the default options in some <select>s. So I can't just add random numbers to the end of some image URLs, for example.
我主要关心的内容是页面文本和一些<select>s中的默认选项。因此,例如,我不能只在某些图像 URL 的末尾添加随机数。
Update:
更新:
I followed the suggestions I've gotten so far:
我遵循了迄今为止得到的建议:
- I'm sending nocache headers (see below)
I'm including a timestamp URL parameter and redirecting to a new one if the page is reloaded after 2 seconds, like this:
$timestamp = $_GET['timestamp']; if ((time()-$timestamp) > 2) { header('Location:/intranet/admin/manage_skus.php?timestamp='.time()); }
- 我正在发送 nocache 标头(见下文)
如果页面在 2 秒后重新加载,我将包含一个时间戳 URL 参数并重定向到一个新的参数,如下所示:
$timestamp = $_GET['timestamp']; if ((time()-$timestamp) > 2) { header('Location:/intranet/admin/manage_skus.php?timestamp='.time()); }
Now Firebug shows that the headers specify no cache, but the problem persists. Here are the response headers for the page:
现在 Firebug 显示标头没有指定缓存,但问题仍然存在。以下是页面的响应标头:
Date Fri, 25 Sep 2009 20:41:43 GMT
Server Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.8
X-Powered-By PHP/5.2.8
Expires Mon, 20 Dec 1998 01:00:00 GMT
Last-Modified Fri, 25 Sep 2009 20:41:43 GMT
Cache-Control no-cache, must-revalidate
Pragma no-cache
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Transfer-Encoding chunked
Content-Type text/html
回答by Anatoliy
Add current timestamp as parameter of url, e.g.
添加当前时间戳作为 url 的参数,例如
http://server.com/index.php?timestamp=125656789
回答by Craig Treptow
I think this tells you what you want:
我想这会告诉你你想要什么:
http://www.thesitewizard.com/archive/phptutorial2.shtml
http://www.thesitewizard.com/archive/phptutorial2.shtml
Look for "Preventing the Browser From Caching"
查找“防止浏览器缓存”
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
回答by Martin v. L?wis
You should send the following header:
您应该发送以下标头:
Cache-control: no-cache
in the HTTP response.
在 HTTP 响应中。
回答by Pascal Thivent
You could add these headers:
您可以添加这些标题:
Cache-Control: no-cache
And (for backward compatibility with HTTP/1.0 clients)
并且(为了与 HTTP/1.0 客户端向后兼容)
Pragma: no-cache
回答by Craig Treptow
Here's another take that isn't PHP specific.
这是另一个不是 PHP 特定的。
Try this in your <head> </head>section:
在你的<head> </head>部分试试这个:
<meta http-equiv="cache-control" content="no-cache, no store"/>
<meta http-equiv="Expires" Content="Mon, 25 May 2009 19:07:03 GMT">
Found that at the end of a long thread here:
发现在一个长线程的末尾:
http://forums.mozillazine.org/viewtopic.php?f=25&t=673135&start=75
http://forums.mozillazine.org/viewtopic.php?f=25&t=673135&start=75
回答by Ken Keenan
Use the header() function. You have to set a few to cover all browsers; see http://www.php.net/manual/en/function.header.php#75507
使用 header() 函数。您必须设置一些以覆盖所有浏览器;见http://www.php.net/manual/en/function.header.php#75507

