问题
Duplicate:
Why isn’t my javascript & css caching ?
I'm noticing that I'm only receiving 304 HTTP codes (cached content) for images but not JavaScript or CSS.
My .htaccess file is:
Options -Indexes
Options +FollowSymLinks
# Enable ETag
FileETag MTime Size
# Set expiration header
ExpiresActive on
ExpiresDefault "access plus 1 week"
# Compress some text file types
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/x-javascript text/javascript application/javascript application/json
# Deactivate compression for buggy browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Set header information for proxies
Header append Vary User-Agent
Anyone know why only images are caching and not my JavaScript or CSS?
回答1:
Use a snooping proxy like Fiddler to see what the browser is requesting of your server and the headers that are being returned.
You should see an initial request with a "200" status returned. Then you should see a request from the browser to verify its cache. The return header should indicate that the browser cache is still good and should not include the page content.
回答2:
Use Firebug for Firefox, have a look at the network tab. You will not see a network connection for cached content on reload.
回答3:
I usually use this addon:
https://addons.mozilla.org/en-US/firefox/addon/3829
it lets you monitor the HTTP requests, if the file isn't being requested then its cached. Also if your still having caching issues make sure your not using a funky proxy. (i have ran into issues where the proxy was losing the ETag so it was never caching)
回答4:
I'll use either Firebug or TamperData to monitor HTTP request. The latter is useful in the case where there might be redirects involved, which Firebug won't necessarily tell you.
来源:https://stackoverflow.com/questions/841091/htaccess-not-working-only-caching-images-and-not-js-or-css