开发者

htaccess 'Header unset Last-Modified' caching issue

开发者 https://www.devze.com 2022-12-25 07:04 出处:网络
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)$\">

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 thi开发者_JS百科s (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.


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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消