12

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?

masegaloeh
  • 17,978
  • 9
  • 56
  • 104

2 Answers2

20

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:

# Add Proper MIME-Type for Favicon
AddType image/x-icon .ico

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

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

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

  • +1 This absolutely works. Make sure to _clear your cache_ though people, I thought this didn't work until I manually cleared my cache. Not sure why a hard refresh didn't do it but whatever. – Yes Barry Sep 21 '12 at 07:14
0

This here works for me:

# Cache the following content for 1 month (4 Weeks)
<FilesMatch "\.(jpg|jpeg|png|gif|ico)$">
Header set Cache-Control "max-age=2419200, public"
</FilesMatch>
BastianW
  • 2,848
  • 4
  • 19
  • 34