过期标头无效:使用其他地方的设置

时间:2010-03-30 16:01:47

标签: .htaccess caching header

我有一个伪装成JS的PHP脚本,以便动态地包含和打包各种JS文件作为一个。

我无法将其缓存:标题似乎不想设置。

$expires = 60*60*24*14;
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');

我在脚本的顶部有这个。我也有.htaccess:

ExpiresByType application/x-javascript M2592000

但是,它不起作用,文件的HTTP响应如下:

Date    Tue, 30 Mar 2010 15:54:52 GMT
Server  Apache
X-Powered-By    PHP/5.2.12
Pragma  no-cache
Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires Thu, 19 Nov 1981 08:52:00 GMT
Vary    Accept-Encoding
Content-Encoding    gzip
Connection  close
Transfer-Encoding   chunked
Content-Type    application/x-javascript

如何让它缓存此内容?

1 个答案:

答案 0 :(得分:1)

我在脚本中使用了一个会话变量。 session_start()显然会阻止页面可缓存,如果您考虑它,这是有道理的。删除session_start()使脚本运行并变为可缓存。