简体   繁体   中英

apache caching js files

I've configured Apache under windows to enable cache like this

    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>

When I try to open js file directly in browser (to test) by refreshing again and again then each time I get response status 200 with Firebug. Its not sending status "304 Not Modified". Have u any idea how can I achieve this. Following is the output of Firebug headers.

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

The request contains a if-modified-since -header:

 Sat, 13 Aug 2011 01:03:42 GMT

But the response contains a last-modified -header with a time later than that:

Sat, 13 Aug 2011 01:18:15 GMT

..so the file has to be loaded again.

Try unsetting the last-modified-header: http://www.askapache.com/htaccess/apache-speed-last-modified.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM