google-chrome - 如何强制 chrome 在选项卡上显示精确大小的图标 (16x16)?
问题描述
我在我的网页上设置了多图标配置,但 chrome 不在选项卡上显示 16x16 文件,而是以 16x16 显示 32x32。为什么 ?这是一种强制它显示 16x16 的方法吗?以 16x16 显示的 32x32 模糊...
这是我的代码:
<link rel="shortcut icon" href="/relativepath/favicon.ico" type="image/x-icon">
<link rel="icon" sizes="16x16" href="/relativepath/favicon.png" type="image/png">
<link rel="icon" sizes="32x32" href="/relativepath/favicon-32.png" type="image/png">
<link rel="icon" sizes="64x64" href="/relativepath/favicon-64.png" type="image/png">
<link rel="icon" sizes="96x96" href="/relativepath/favicon-96.png" type="image/png">
<link rel="icon" sizes="196x196" href="/relativepath/favicon-196.png" type="image/png">
<link rel="apple-touch-icon" sizes="152x152" href="/relativepath/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="60x60" href="relativepath/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="76x76" href="/relativepath/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/relativepath/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/relativepath/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/relativepath/apple-touch-icon-144x144.png">
解决方案
TL; DR
Invert your 16x16 and 32x32 PNG icons declarations (so the 32x32 becomes the first one)
The Long Answer
Unfortunately, Chrome has two issues (324820 and 112941) related to the sizes
attribute. In short: it does not support sizes
and loads all icons.
Years ago, I played with favicon declarations order while implementing RealFaviconGenerator. I put the smallest PNG icon last and second smallest first, in order to prevent the non-supporting browsers from using a high definition icon (at that time there was a 192x192 PNG icon for Android Chrome). As of today, when using RealFaviconGenerator, Chrome picks the 32x32 PNG icon.
If you are going to test a lot of configurations, I suggest you to:
- Use a different (sub)domain name for each test. Favicon caching is just too much pain. Using a tool such as ngrok can do this as a side effect: simply restart it before each new experiment. Or you can configure a wildcard on an existing domain.
- Instead of having the same image in various sizes, use different icons, as done in the favicon compatibility test. For example, make the 16x16 icon a yellow square, while the 32x32 icon will be green. That way, you can instantly see what is used.
推荐阅读
- python - 字典到数组的转换,其中数据帧不产生正确的行输出
- javascript - 组件的 Svelte 导出功能
- python - 将 tkinter 按钮转换为菜单项
- powershell - 创建带有添加选项的快捷方式
- c++ - 虽然循环在 Dev C++ 中没有按预期运行
- c# - 是否可以在 CustomAttribute 中重新绑定 IPrincipal?
- vba - 如何在多个帐户上运行规则?
- sql - 雪花任务没有给我任何错误,但表是空的
- javascript - Asp.net 项目 - Javascript 按钮可点击但不执行该功能
- reactjs - 在从 `useEffect` 调用的`useCallback` 中设置和使用状态时的无限循环