1. I am setting cache expiry period for images on my server using some .htaccess code. The thing is, when I checked the cache-expiry period of images on some popular websites, it's mostly between 31536000 (1 year)
to 15552000 (180 days)
to 5184000 (60 days)
. A cache-expiry header is used to tell the browser to sto开发者_运维问答re the static files in its cache for a certain period, right? Then WTH?! Why are these websites setting such long expiry? Am I missing something here?
2. Also which of these below (.htaccess codes) is better in your opinion?
<FilesMatch "\.(ico|jpg|jpeg|png|gif|swf|pdf)$">
ExpiresDefault A0
Header set Cache-Control "max-age=5184000, public, must-revalidate, proxy-revalidate"
</FilesMatch>
<--- OR --->
# Expire images header
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A5184000
ExpiresByType image/png A5184000
ExpiresByType image/jpg A5184000
ExpiresByType image/jpeg A5184000
ExpiresByType image/ico A5184000
ExpiresByType image/swf A5184000
ExpiresByType image/pdf A5184000
EDIT: 3. How to set expiry-headers for external files? for example, js and css files from external sources? (many do not have a set cache expiry period, I checked)
Looking for a knowledgeable answer. Thanks.
I'm not sure I can answer your question exactly, but this link describes what you're after.
You can set cache-control on your second example for js and css files too. According to the answer the second format is better because it is not dependent on the file extension, and other things explained in the article.
Regarding long expiry times, that's the choice of the webmaster I guess but I also came across another option which is not mentioned in the article: Cache Control: Public
which is essentially meant to force your images to be stored on ISPs servers all over the world, as far as I can see. Perhaps the long expiry times are older tech to accomplish something similar.
精彩评论