Getting rid of favicon.ico
Most of my sites don't have favicons. I think it's nice to have one, but designing an icon that looks good and matches a site theme takes time and effort better spent elsewhere. My pixel-pushing powers are not at a level where making one is easy and I'd rather have the default icon than an ugly one, thank you very much.
When Internet Explorer introduced favicons, it regrettably used fixed location probing to detect the presence of page icons. Other browsers have since adopted the feature, and if my server logs are any indication Firefox is even more obsessive-compulsive about them than IE. Nearly every browser visit will be associated with requests for favicon.ico, which translates into a lot of requests on a busy site.
What does this mean for sites without favicons? For each and every one of those requests Apache will look for the file favicon.ico, find that it still does not exist, and return a 404 Not Found error page. If you use custom error documents (a user-friendly thing to do), that page could very well be several kilobytes in size and will not be seen by the visitor. A further annoyance is that the aforementioned failed file-finding attempt will clutter up the error log with reams of "File does not exist" errors.
You can get rid of the unnecessary processing and traffic as well as the error log entries by using the following Apache configuration incantations:
# Don't bother looking for favicon.ico Redirect 404 /favicon.ico # Don't bother sending the custom error page for favicon.ico <Location /favicon.ico> ErrorDocument 404 "No favicon </Location>
Redirect directive causes Apache to immediately generate a 404 error when /favicon.ico is requested, thereby avoiding the
stat calls and the error log entries caused by their inevitable failure. Whatever error document would normally be used for these 404 error response is overridden with a brief text message in the
Unlike the commonly suggested workaround of creating a dummy favicon.ico file, this technique will return the appropriate HTTP status code rather than pretending to send an icon. I don't know of any browsers that will choke on a 0-byte favicon.ico, but lying to the client is bad form – at least when there's no good reason to do so.
Requests for favicon.ico will still be logged in your access log; you could filter them out with conditional logging if so desired (I prefer to keep them in the log). These Apache directives will work fine in
VirtualHost blocks, so the
Redirect can be applied only for those sites that lack favicons without affecting the functionality of other sites.
18 February, 2005
Feedback is closed for this entry.