Html 您是否必须包含 <link rel="icon" href="favicon.ico" type="image/x-icon" />?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6644684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Do you have to include <link rel="icon" href="favicon.ico" type="image/x-icon" />?
提问by user784637
I didn't include the following line of code in my head tag, however my favicon still appears in my browser:
我没有在 head 标签中包含以下代码行,但是我的 favicon 仍然出现在我的浏览器中:
<link rel="icon" href="favicon.ico" type="image/x-icon" />
What's the purpose of including it?
包含它的目的是什么?
采纳答案by Brian Graham
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.
如果您不调用收藏夹图标 ,则favicon.ico
可以使用该标记来指定实际路径(如果您在images/
目录中拥有它)。浏览器/网页favicon.ico
默认在根目录中查找。
回答by siburb
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:
将文件命名为“favicon.ico”并将其放在您网站的根目录中是 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
方法 2(不建议):将网站图标放在预定义的 URI
指定网站图标的第二种方法依赖于使用预定义的 URI 来标识图像:“/favicon”,它与服务器根目录相关。此方法有效,因为某些浏览器已被编程为使用该 URI 查找网站图标。
W3C - 如何向您的网站添加收藏夹图标
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.
因此,为了涵盖所有情况,除了添加“rel”属性并将其指向同一个 .ico 文件的推荐方法之外,我总是这样做。
回答by nilsi
I use it for two reasons:
我使用它有两个原因:
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" />
In case I need to specify the path.
例如,我可以通过添加查询参数来强制刷新图标
?v=2
。像这样:<link rel="icon" href="/favicon.ico?v=2" type="image/x-icon" />
如果我需要指定路径。
回答by Nicole
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.
简单地将它添加到根文件夹后可以正常工作,但我发现如果我需要更改收藏夹图标,更新可能需要几天时间......即使是缓存刷新也无法解决问题。
回答by user3907900
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.
许多人将他们的 cookie 路径设置为 /。这将导致每个图标请求发送站点 cookie 的副本,至少在 chrome 中。将您的网站图标定位到您的无 cookie 域应该可以解决这个问题。
<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:
有关设置无 cookie 域的信息: