我已经在windows下配置了Apache以启用这样的缓存
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so
ExpiresActive On
ExpiresDefault "access plus 3 days"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
<IfModule mod_headers.c>
# YEAR
<FilesMatch "'.(ico|gif|jpg|jpeg|png|flv|pdf)$">
Header set Cache-Control "max-age=29030400"
</FilesMatch>
# WEEK
<FilesMatch "'.(js|css|swf)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
# 45 MIN
<FilesMatch "'.(html|htm|txt)$">
Header set Cache-Control "max-age=2700"
</FilesMatch>
</IfModule>
当我尝试打开js文件直接在浏览器(测试)通过刷新一次又一次,然后每次我得到响应状态200与Firebug。它没有发送状态"304未修改"。你知道我怎样才能做到这一点吗?以下是Firebug头文件的输出。
Response Header
Date Sat, 13 Aug 2011 01:18:15 GMT
Server Apache/2.2.19 (Win32) PHP/5.3.6
Last-Modified Sat, 13 Aug 2011 01:18:15 GMT
Etag W/"100000000171d-34f08-4aa5f022d9780"
Accept-Ranges bytes
Content-Length 216840
Cache-Control max-age=604800
Expires Tue, 16 Aug 2011 01:18:15 GMT
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type application/javascript
Request Header
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Cookie PHPSESSID=5k947khv1j27itd7mtp5evtg07
If-Modified-Since Sat, 13 Aug 2011 01:03:42 GMT
If-None-Match W/"100000000171d-34f08-4aa5f022d9780"
Cache-Control max-age=0
请求包含一个if-modified-since-header:
Sat, 13 Aug 2011 01:03:42 GMT
但是响应包含最后修改的头,时间晚于此:
Sat, 13 Aug 2011 01:18:15 GMT
. .所以文件必须重新加载。
尝试取消last-modified-header: http://www.askapache.com/htaccess/apache-speed-last-modified.html