Do you have to include <link rel="icon" href="favicon.ico" type="image/x-icon" />?

HtmlFavicon

Html Problem Overview


I didn't include the following line of code in my head tag, however my favicon still appears in my browser:

<link rel="icon" href="favicon.ico" type="image/x-icon" />

What's the purpose of including it?

Html Solutions


Solution 1 - Html

If you don't call the favicon, favicon.ico, you can use that tag to specify the actual path (incase you have it in an images/ directory). The browser/webpage looks for favicon.ico in the root directory by default.

Solution 2 - Html

You should in fact do both, so that all browsers will find the icon.

Naming the file "favicon.ico" and putting it in the root of your website is the method "discouraged" by W3C:

> Method 2 (Discouraged): Putting the favicon at a predefined URI
A second method for specifying a favicon relies on using a predefined URI to identify the image: "/favicon", which is relative to the server root. This method works because some browsers have been programmed to look for favicons using that URI.
W3C - How to add a favicon to your site

So, to cover all situations, I always do that in addition to the recommended method of adding a "rel" attribute and pointing it to the same .ico file.

Solution 3 - Html

I use it for two reasons:

  1. I can force a refresh of the icon by adding a query parameter for example ?v=2. like this: <link rel="icon" href="/favicon.ico?v=2" type="image/x-icon" />

  2. In case I need to specify the path.

Solution 4 - Html

Simply adding it to the root folder works after a fashion, but I've found that if I need to change the favicon, it can take days to update... even a cache refresh doesn't do the trick.

Solution 5 - Html

Many people set their cookie path to /. That will cause every favicon request to send a copy of the sites cookies, at least in chrome. Addressing your favicon to your cookieless domain should correct this.

<link rel="icon" href="https://cookieless.MySite.com/favicon.ico" type="image/x-icon" />

Depending on how much traffic you get, this may be the most practical reason for adding the link.

Info on setting up a cookieless domain:

http://www.ravelrumba.com/blog/static-cookieless-domain/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser784637View Question on Stackoverflow
Solution 1 - HtmlNahydrinView Answer on Stackoverflow
Solution 2 - HtmlsiburbView Answer on Stackoverflow
Solution 3 - HtmlnilsiView Answer on Stackoverflow
Solution 4 - HtmlNicoleView Answer on Stackoverflow
Solution 5 - Htmluser3907900View Answer on Stackoverflow