.htaccess not working - only caching images and not JS or CSS [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-06 04:26:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!