Expires headers not working: using settings from elsewhere
I have a PHP script masquerading as JS in order to dynamically include and pack various JS files to serve as one.
I'm having trouble getting it to cache: the headers don't seem to want to set.
$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');
I have that at the top of the script. I also have in .htaccess:
ExpiresByType application/x-javascript M2592000
However, it's not working and the HTTP response for the file is as follows:
Date Tue, 30 Mar 2010 15:54:52 GMT
Server Apache
X-Powered-By PHP/5.2.12
Pragma no-cache
Cache-Contro开发者_如何转开发l 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
How can I get it to cache this content?
I was using a session variable in the script. The session_start() apparently stops a page from being cacheable, which makes sense if you think about it. Removing session_start() made the script behave and become cacheable.
精彩评论