Is putting your favicon.ico file in a non-root path a bad idea?

HtmlHttpCross BrowserBrowser

Html Problem Overview


When and how do browsers request the favicon.ico file? Do they always check for it in root, or do they read the content of the webpage first to see if the page specifies the location?

I have my favicon.ico path in /images There is the following tag in each of my pages:

<link rel="shortcut icon" href="images/favicon.ico">

When I load the page in my browser, it seems to work (I can see the file), but I don't know whether they are making bad requests to my root folder first (where the file doesn't exist), and are later making a request to the link.

I want to minimze 404's and wasted bandwidth, by the browser making incorrect calls to my site.

EDIT: I'm looking for some insight into how browsers work, and request this file, so my site structure is efficient.

Html Solutions


Solution 1 - Html

Remember that not all requests to your site are for HTML pages! Requests for non-HTML content, like bare image files (e.g, viewing http://example.com/image.jpeg directly in the browser), cannot see a <link> tag. Therefore, they must fall back to searching for the shortcut icon in the standard location at /favicon.ico.

This still doesn't mean that this needs to be the canonical location, though! You can still keep it in /images/favicon.ico if you want - just make sure that a redirect is in place from /favicon.ico to wherever your preferred location is.

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
QuestionRahul IyerView Question on Stackoverflow
Solution 1 - Htmluser149341View Answer on Stackoverflow