Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

migrated from stackoverflow.com Nov 19 '09 at 7:22

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

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

share|improve this answer
    
+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. –  mmmshuddup Sep 21 '12 at 7:14
add comment

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>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.