I have implemented Expires headers via mod_expires on my Apache server and have successfully created expires headers for most file types, however I am having trouble with the favicon.

I initially tried adding a set of instructions for the .ico files but when checking via YSlow it has no expiry set.

When this didn't work I amended it to be a GIF, however this seems to have the same issue.

Other gif's on the website have correctly set expires headers (accoridng to YSlow at least).

Can anyone shed any light on this situation?

share|improve this question

 

方法如下:

If you're using Apache, just add a MIME-Type for the favicon in your website's .htaccess file or to Apache's mime.types file:

vim /etc/httpd/conf/httpd.conf
# Add Proper MIME-Type for Favicon
AddType image/x-icon .ico

Then, set the Expires header a few month(s) in the future:

vim /etc/httpd/conf/httpd.conf

# Enable Apache's mod_expires Module
ExpiresActive On
ExpiresByType image/x-icon "access plus 1 month"

或者在 wordpress/ 目录下 vim  ./wordpress./.htaccess

<IfModule mod_expires.c> 
ExpiresActive On 
ExpiresDefault A3600
ExpiresByType image/x-icon A2592000 
ExpiresByType application/x-javascript A2592000 
ExpiresByType application/javascript A2592000 
ExpiresByType text/javascript A2592000 
ExpiresByType image/gif A2592000 
ExpiresByType image/jpeg A2592000 
ExpiresByType image/png A2592000 
ExpiresByType text/css A604800 
ExpiresByType text/php A604800 
ExpiresByType text/css.php A604800 
ExpiresByType text/plain A86400
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType video/x-flv A2592000 
ExpiresByType application/pdf A2592000 
ExpiresByType application/ico A2592000 
ExpiresByType application/php A2592000 
ExpiresByType text/html A3600
</IfModule> 

After clearing your browser's cache and reloading the page, you should see the favicon.ico file being served with the Cache-Control header being set to a date (specified in seconds) in the future:

Content-Type image/x-icon
Cache-Control: max-age=2592000

For related information, see the YSlow documentation on Making Your favicon.ico Small and Cacheable at: http://developer.yahoo.com/performance/rules.html#favicon

参考推荐:

favicon.ico不显示的情况与浏览器的缓存