tags:

views:

86

answers:

2

I am already using the standard way of adding a favicon:

<link rel="icon" type="image/gif" href="/graphics_card/favicon.gif">
<link rel="shortcut icon" href="/graphics_card/favicon.ico">

so the favicon.gif and .ico are both supposed to reside on

/graphics_card

However, I found that IE 8 (or maybe other IE) cannot show it, (update: no matter how many times I pressed CTRL-F5, or clear the browser cache), but as soon as the .ico file is present in that directory where the index.html is, then it will show.

So if it is

http://www.example.com/graphics_card/nvidia/index.html

there needs to be a favicon.ico in

/graphics_card/nvidia/

too. I ended up specifying it as

<link rel="icon" type="image/gif" href="/graphics_card/favicon.gif">
<link rel="shortcut icon" href="favicon.ico">

and just put a favicon.ico in that directory. Is this the standard way?

+1  A: 

No, you can put it anywhere if you specify it in the tag. However, for IE, you need to give a fully qualified URL (i.e. not a relative url).

jeffamaphone
Really? I was working on an answer where I was going to mention IE ignores `<link rel="shortcut icon">`...is this new behavior I'm unaware of?
Jed Smith
Funny how Microsoft more or less invented the favicon, but their browsers have such trouble with them.
Frank DeRosa
@Jed Smith: IE requires the rel="shortcut icon", even though using a space violates the standard (according to the link in jeffamaphone's post). All the other browsers look for a rel="icon" value.
Frank DeRosa
@Frank? really? some people say MS is the only one following the standard of W3C in the case of favicon...
動靜能量
@Frank: Yeah, you must say "shortcut icon".@Jian: There is a W3C standard for favicon? AFAIK some IE PM just pulled it out of their arse late in a ship cycle. Oh, I see there is a draft, but it pretty much agrees with what we've said here.
jeffamaphone
A: 

You can play it anywhere else and use the <link> tag to refer to it.

However it is good practice to put it on the domain root e.g. http://example.com/favicon.ico, because modern browsers will actually do a call to that file when loading pages to load the icon first.

thephpdeveloper
That's actually NOT a good practice. The W3C frowns upon pollution of the URI namespace in this way. Furthermore, not all users have access to the root of their domain (e.g. www.example.com/users/billybob, schools, geocities, etc).
jeffamaphone
it is good to have one there no matter what, because either way the server still have to return the request on that. Do your homework on this. You can easily find this on https://developer.yahoo.com/performance/rules.html#favicon
thephpdeveloper
Internet Explorer will remember that you had 404 and not re-request it. I imagine the latest versions of the other browsers do the same. You can put it in the root to avoid the 404, but you should still have a <link> tag pointing at it.
jeffamaphone