正确的MIME类型为favicon.ico? [英] Correct MIME Type for favicon.ico?

查看:197
本文介绍了正确的MIME类型为favicon.ico?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据互联网号码分配机构(IANA)的规定,所有的.ico文件都属于MIME类型 image / vnd.microsoft.icon 。 (来源



例如
< link rel =icontype =image / vnd.microsoft.iconhref =favicon.ico/>

然而,精明的互联网大师 Paul Irish 声称这是错误的,它实际上会是 image / x-icon / code>。 (来源



EG
< link rel =icontype =image / x-iconhref =favicon.ico/>



我知道你可以逃脱不包括一个类型的.ico文件,但如果你打算包括一个,它应该是什么?实际上IANA类型的服务存在任何问题吗? 解决方案

当您提供要使用的.ico文件时作为一个图标,这并不重要。所有主流浏览器都能正确识别这两种MIME类型。所以你可以把:

 <! -  IE  - > 
< link rel =快捷图标type =image / x-iconhref =favicon.ico/>
<! - 其他浏览器 - >
< link rel =icontype =image / x-iconhref =favicon.ico/>

或与 image / vnd.microsoft.icon ,它将适用于所有浏览器。注意:MIME类型 image / x-icon 没有IANA规范,所以它确实出现它比 image / vnd.microsoft.icon 更加非官方。



唯一的情况是不同的是,如果您尝试在< img> 标签中使用.ico文件(这非常不寻常)。
根据以前的测试,一些浏览器只有在MIME类型 image / x-icon 时才会将.ico文件显示为图像。最近的测试显示:在两种内容类型中,Chromium,Firefox和Edge都很好,但IE11并不适用。如果可以,只要避免使用 ico 文件作为图像,请使用 png


According to the Internet Assigned Numbers Authority (IANA), all .ico file falls under the MIME type image/vnd.microsoft.icon. (Source)

E.g. <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)

E.g. <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?

解决方案

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:

<!-- 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.

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.

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.

这篇关于正确的MIME类型为favicon.ico?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆