.htaccess 不起作用 - 仅缓存图像而不缓存 JS 或 CSS
复制:
我注意到我只收到图像的 304 HTTP 代码(缓存内容),而不是 JavaScript 或 CSS。
我的 .htaccess 文件是:
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
有人知道吗为什么只有图像被缓存,而不是我的 JavaScript 或 CSS?
Duplicate:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 Fiddler 等监听代理来查看浏览器向服务器请求的内容以及返回的标头。
您应该会看到返回状态为“200”的初始请求。 然后您应该会看到来自浏览器的请求来验证其缓存。 返回标头应表明浏览器缓存仍然良好,并且不应包含页面内容。
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.
使用 Firebug for Firefox,查看网络选项卡。 重新加载时您将看不到缓存内容的网络连接。
Use Firebug for Firefox, have a look at the network tab. You will not see a network connection for cached content on reload.
我通常使用这个插件:
https://addons.mozilla.org/en- US/firefox/addon/3829
它可以让您监视 HTTP 请求,如果文件没有被请求,则它会被缓存。 另外,如果您仍然遇到缓存问题,请确保您没有使用时髦的代理。 (我遇到过代理丢失 ETag 的问题,因此它从不缓存)
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)
我将使用 Firebug 或 TamperData 来监视 HTTP 请求。 后者在可能涉及重定向的情况下很有用,而 Firebug 不一定会告诉您这一点。
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.