htaccess 'Header unset Last-Modified' caching issue

徘徊边缘 提交于 2019-12-12 09:44:47

问题


Im trying to set up some cache control options in my htaccess file.

At the moment it looks like this:

<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf|css|js|html|pdf)$">
Header set Cache-Control "max-age=2592000, public, must-revalidate"
Header unset ETag
FileETag None
</FilesMatch>

However I read about (and wanted to add) Header unset Last-Modified, so it would be something like:

<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf|css|js|html|pdf)$">
Header set Cache-Control "max-age=2592000, public, must-revalidate"
Header unset Last-Modified
Header unset ETag
FileETag None
</FilesMatch>

However, using this (according to Firebug) doesnt make anything load from the cache at all (whereas the first technique loads everything)

Am I doing something wrong? The syntax seems to be right.

A.


回答1:


The syntax is correct, but the usage isn't. According to "Speed Tips: Remove Last-Modified Header" found here: http://www.askapache.com/htaccess/apache-speed-last-modified.html

If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since and If-None-Match requests and their 304 Not Modified Responses, so a file will stay cached without checking for updates until the Expires header indicates new content is available!

Also:

By removing both the ETag header and the Last-Modified headers from your static files (images, javascript, css) browsers and caches will not be able to validate the cached version of the file vs. the real version. By also including a Cache-Control header and Expires header, you can specify that certain files be cached for a certain period of time, and you magically (this is a really unique trick I promise) eliminate any validation requests!!

Refer to the original link for more details.




回答2:


One use case for removing Last-Modified would be if a resource uses the new cache-control: immutable directive which instructs caches that the resource will never change (e.g. when controlling file versions with hashes). Micro optimizations...



来源:https://stackoverflow.com/questions/2546711/htaccess-header-unset-last-modified-caching-issue

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