I am building a linklist, that automatically retrieves favicons of linked sites and displays them next to them. Now, I noticed, that some sites (e.g. this very one, doctype.org) don't have a favicon.ico in their root directory. Yet the browser shows an icon next to the URL.
I thought this was a de facto standard, having the favicon in the root directory. What are the advantages of cloaking it? And how is it done? (Just asking out of interest).
It's not cloaking, it's the proper way to do it.
Putting a .ico file in the root isn't a good way to do a fundamental part of a website because:
- It's not a well known format (no registered MIME type)
- Assuming content is always in the same place is against the ideas set forward in the Architecture of the World Wide Web
- The format that was put forward to describe it's position didn't follow the spec
The proper way is to put in the
head of the page code like:
<link rel="icon" type="image/vnd.microsoft.icon" href="http://example.com/image.ico"> <link rel="icon" type="image/png" href="http://example.com/image.png"> <link rel="icon" type="image/gif" href="http://example.com/image.gif">
<link rel="icon" type="image/vnd.microsoft.icon" href="/somepath/image.ico" /> <link rel="icon" type="image/png" href="/somepath/image.png" /> <link rel="icon" type="image/gif" href="/somepath/image.gif" />
This specifies it's the icon, has the MIME type (note that ico has the vendor prefix as it's not standard), and then the path.
By parsing the href section of the link with rel = icon, you will be able to get the favicon more correctly.
It is still a good idea to have the icon at /favico.ico, otherwise 404 responses to requests for that file will constitute 95% off your error log (or to put it another way, your error logs will be much bigger than they need to be).
Internet Explorer requests favicon.ico for every page request it sends, and has no way of turning that off. Opera requests it by default but you can disable it. I'm not sure about Firefox, Safari, Chrome etc.
if you checked the source of doctype.com, you'll find:
<link rel="icon" type="image/png" href="/images/favicon.png?1" />
which is used to specify the favicon.
More info in wikipedia
Ok, yes, but why not just use .ico and put it in the root? Is there any advantage to that? (Sorry, I was stupid, didn't even think of checking the source o_O... )