Html favicon.ico 的正确 MIME 类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13827325/
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
Correct MIME Type for favicon.ico?
提问by Chuck Le Butt
According to the Internet Assigned Numbers Authority(IANA), all .ico file falls under the MIME type image/vnd.microsoft.icon
. (Source)
根据互联网号码分配机构(IANA),所有 .ico 文件都属于 MIME 类型image/vnd.microsoft.icon
。(来源)
E.g.
<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" />
例如
<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" />
However, savvy internet guru, Paul Irish, claims this is wrong, and that it would actually be image/x-icon
. (Source)
然而,精明的互联网大师保罗爱尔兰声称这是错误的,而且实际上是image/x-icon
。(来源)
E.g.
<link rel="icon" type="image/x-icon" href="favicon.ico" />
例如
<link rel="icon" type="image/x-icon" href="favicon.ico" />
I know you can get away with not including a "type" for .ico files, but if you were going to include one, which should it be? Are there actually any problems with serving it as official IANA type?
我知道您可以不包含 .ico 文件的“类型”,但是如果您要包含一个,应该是哪个?将其作为官方 IANA 类型提供实际上有什么问题吗?
回答by mata
When you're serving an .ico file to be used as a favicon, it doesn't matter. All major browsers recognize both mime types correctly. So you could put:
当您提供要用作收藏夹图标的 .ico 文件时,这无关紧要。所有主要浏览器都能正确识别这两种 mime 类型。所以你可以把:
<!-- IE -->
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
<!-- other browsers -->
<link rel="icon" type="image/x-icon" href="favicon.ico" />
or the same with image/vnd.microsoft.icon
, and it will work with all browsers.
或与 相同image/vnd.microsoft.icon
,它将适用于所有浏览器。
Note: There is no IANA specification for the MIME-type image/x-icon
, so it does appear that it is a little more unofficial than image/vnd.microsoft.icon
.
注意:MIME 类型没有 IANA 规范image/x-icon
,因此它确实比image/vnd.microsoft.icon
.
The only case in which there is a difference is if you were trying to use an .ico file in an <img>
tag (which is pretty unusual).
Based on previous testing, some browsers would only display .ico files as images when they were served with the MIME-type image/x-icon
. More recent tests show: Chromium, Firefox and Edge are fine with both content types, IE11 is not. If you can, just avoid using ico
files as images, use png
.
唯一存在差异的情况是,如果您尝试在<img>
标签中使用 .ico 文件(这很不寻常)。根据之前的测试,某些浏览器在使用 MIME 类型时只会将 .ico 文件显示为图像image/x-icon
。最近的测试表明:Chromium、Firefox 和 Edge 对这两种内容类型都很好,而 IE11 则不然。如果可以,请避免使用ico
文件作为图像,使用png
.
回答by Jürgen Steinblock
I think the root for this confusion is well explained in thiswikipedia article.
我认为这种混淆的根源在这篇维基百科文章中得到了很好的解释。
While the IANA-registered MIME type for ICO files is image/vnd.microsoft.icon, it was submitted to IANA in 2003 by a third party and is not recognised by Microsoft software, which uses image/x-icon instead.
虽然 IANA 注册的 ICO 文件 MIME 类型是 image/vnd.microsoft.icon,但它是由第三方于 2003 年提交给 IANA 的,并且无法被 Microsoft 软件识别,微软软件使用 image/x-icon 代替。
If even the inventor of the ICO format does not use the official MIME type, I will use image/x-icon
, too.
如果连 ICO 格式的发明者都不使用官方的 MIME 类型,我也会使用image/x-icon
。
回答by kmcc
I have noticed that when using type="image/vnd.microsoft.icon"
, the favicon fails to appear when the browser is not connected to the internet.
But type="image/x-icon"
works whether the browser can connect to the internet, or not.
When developing, at times I am not connected to the internet.
我注意到在使用 时type="image/vnd.microsoft.icon"
,当浏览器未连接到互联网时,网站图标无法出现。但type="image/x-icon"
无论浏览器是否可以连接到互联网,都有效。在开发时,有时我没有连接到互联网。