如何将过期标头放在超出 JS 文件的 PHP 文件上?
.htaccess
ExpiresActive on
ExpiresByType image/gif A29030400
ExpiresByType image/jpeg A29030400
ExpiresByType image/png A29030400
ExpiresByType text/css A29030400
ExpiresByType application/javascript A29030400
JS文件头
Cache-Control max-age=29030400
Connection Keep-Alive
Date Thu, 18 Oct 2012 09:23:16 GMT
Etag "300000002c8ba-15f-4cc3069c72d00"
Expires Thu, 19 Sep 2013 09:23:16 GMT
Keep-Alive timeout=5, max=94
Server Apache/2.2.22 (Win32) PHP/5.4.3
输出 JS 文件的 PHP 文件的标头
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection Keep-Alive
Content-Length 1195
Content-Type application/javascript
Date Thu, 18 Oct 2012 09:23:16 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive timeout=5, max=100
Pragma no-cache
Server Apache/2.2.22 (Win32) PHP/5.4.3
X-Powered-By PHP/5.4.3
代码 PHP 文件
<?php
header('Content-Type: application/javascript');
$js_output = array('something' => 'some value');
?>
var <?=json_encode($js_output)?>