【问题标题】:Favicons - Best practices [closed]Favicons - 最佳实践[关闭]
【发布时间】:2013-10-02 11:40:52
【问题描述】:

我正在努力了解网站图标、触摸图标以及现在的平铺图标所需的所有这些不同的尺寸和格式。

我读过这篇文章: http://www.jonathantneal.com/blog/understand-the-favicon 但对于在所有设备和浏览器 >= IE8 上看起来相当不错的确切使用方法,我仍然有点模糊。

我认为我应该创建以下内容:

ICO
favicon.ico (32x32)

PNG
favicon.png (96x96)

平铺图标
tileicon.png (144x144)

Apple 触控图标
apple-touch-icon-precomposed.png (152x152)
基于此https://github.com/h5bp/html5-boilerplate/issues/1367

...然后使用此代码为他们服务?

<link rel="apple-touch-icon" href="path/to/touchicon.png">
<link rel="icon" href="path/to/favicon.png">
<!--[if IE]><link rel="shortcut icon" href="path/to/favicon.ico"><![endif]-->
<!-- or, set /favicon.ico for IE10 win -->
<meta name="msapplication-TileColor" content="#D83434">
<meta name="msapplication-TileImage" content="path/to/tileicon.png">

我错过了什么吗?

我不清楚这是否会涵盖 IE 10?

【问题讨论】:

  • 如需最佳答案,请访问 Apple 网站:Apple Developer
  • 在撰写本文时,Apple 网站的初始屏幕图像信息不完整且缺失,可能还有更多信息。
  • 哇 - 这里有很多细节。如果您想要一个简洁快速的简单答案,请参阅stackoverflow.com/a/45301651/661584 可能会有所帮助。谢谢

标签: favicon apple-touch-icon


【解决方案1】:

网站图标比听起来要复杂得多。 10 年前,favicon.ico 是唯一需要的项目。然后是触摸图标,然后是由于各种 iOS 设备屏幕分辨率而导致的多个触摸图标,然后是 Windows 的磁贴图标...

这里的一些答案非常全面 - 并且势不可挡(所有这些,只是为了一个网站图标?)。然而,他们未能指出the 310x310 tile icon for Windows is recommended to be 558x558。而且由于它们是几个月前写的,它们没有提到最近的manifest for Android Chrome M39pinned tab SVG icon for Safari on OS X El Capitan

按平台设计是另一个棘手但被忽视的话题。例如,网站图标通常是透明的。但 iOS 不支持透明度(例如,比较 SO touch icon 和将 SO 添加到 iPhone 的主屏幕时得到的结果)。

出于这些原因,我认为网站图标的最佳做法是手动创建它。相反,请使用工具来自动化整个过程并执行平台指南。

我建议你使用RealFaviconGenerator。它会生成完成工作所需的所有图片和 HTML 代码:

  • 桌面浏览器的favicon.ico 和 PNG 图标
  • 适用于 iOS 和 Android 设备的 Apple 触摸图标
  • Windows 8 磁贴
  • OS X El Capitan 上 Safari 的固定标签图标

例如,它不仅生成msapplication-TileImage图片和标记,还生成IE11支持的更新的browserconfig.xml文件。它还在几个月前进行了更新,以支持 Android Chrome 清单和 Safari OS X El Capitan。

完全披露:我是本网站的作者。

【讨论】:

  • 我刚刚使用了您的网站,非常好。当它不在根目录中时,您应该包含 msapplication-config 元标记:&lt;meta name="msapplication-config" content="../path/to/browserconfig.xml"&gt;
  • 谢谢!关于 browserconfig.xml 的路径:那已经包含在生成的代码中了,不是吗?
  • 文件生成了,但是这行代码没有生成。我刚试过。 顺便感谢您提供的优质服务。
  • @user664833 感谢您的反馈 :) 你的意思是声明 browserconfig.xml 的那一行?
  • 这是有目的的。 browserconfig.xml 不需要声明,只要它在站点的根目录中即可。 IE 会自动查找它。在其他情况下(当您在选项中输入特定路径时),将生成声明。
【解决方案2】:

以下是移动设备和平板电脑网站图标的完整(据我所知)示例:

<!-- non-retina iPhone pre iOS 7 -->
<link rel="apple-touch-icon" href="icon57.png" sizes="57x57">
<!-- non-retina iPad pre iOS 7 -->
<link rel="apple-touch-icon" href="icon72.png" sizes="72x72">
<!-- non-retina iPad iOS 7 -->
<link rel="apple-touch-icon" href="icon76.png" sizes="76x76">
<!-- retina iPhone pre iOS 7 -->
<link rel="apple-touch-icon" href="icon114.png" sizes="114x114">
<!-- retina iPhone iOS 7 -->
<link rel="apple-touch-icon" href="icon120.png" sizes="120x120">
<!-- retina iPad pre iOS 7 -->
<link rel="apple-touch-icon" href="icon144.png" sizes="144x144">
<!-- retina iPad iOS 7 -->
<link rel="apple-touch-icon" href="icon152.png" sizes="152x152">
<!-- Win8 tile -->
<meta name="msapplication-TileImage" content="favicon-144.png">
<meta name="msapplication-TileColor" content="#B20099"/>
<meta name="application-name" content="name" />

<!-- IE11 tiles -->
<meta name="msapplication-square70x70logo" content="tile-tiny.png"/>
<meta name="msapplication-square150x150logo" content="tile-square.png"/>
<meta name="msapplication-wide310x150logo" content="tile-wide.png"/>
<meta name="msapplication-square310x310logo" content="tile-large.png"/>

对于 IE11,here 是一个常见问题解答

【讨论】:

  • 哦,太棒了 - IE11 也有新的!感谢您发布信息。
  • 但这不包括“apple-touch-icon-precomposed.png”和“apple-touch-icon.png”
  • +1 但我不确定这是否是最佳实践,尽管它是彻底的。有关最佳实践 (IMHO) 和更实用的方法,请参阅下面 Neil Robertson 建议的出色备忘单。
  • 您是否有机会更新答案,使其也适用于 6 和 6+?或者上面的代码应该工作吗?
  • 看我的回答stackoverflow.com/a/45301651/661584 容易多了。可能有帮助。谢谢
【解决方案3】:

您可以为各种设备设置许多不同的图标甚至启动画面。这个答案涵盖了如何支持他们所有人。

以下是我使用的一些 sn-ps,以及我收集信息的相关链接。请参阅 my blog 了解更多信息以及有关 ASP.NET MVC Boilerplate 项目模板的更多信息,所有这些都是开箱即用的内置(包括示例图像文件)。

将以下标记添加到您的 html 头部。注释掉的部分完全是可选的。虽然建议未注释的部分涵盖所有图标用法。不要害怕,如果是 cmets 帮助你的话。

<!-- Icons & Platform Specific Settings - Favicon generator used to generate the icons below http://realfavicongenerator.net/ -->
<!-- shortcut icon - It is best to add this icon to the root of your site and only use this link element if you move it somewhere else. This file contains the following sizes 16x16, 32x32 and 48x48. -->
<!--<link rel="shortcut icon" href="favicon.ico">-->
<!-- favicon-96x96.png - For Google TV. -->
<link rel="icon" type="image/png" href="/content/images/favicon-96x96.png" sizes="96x96">
<!-- favicon-16x16.png - The classic favicon, displayed in the tabs. -->
<link rel="icon" type="image/png" href="/content/images/favicon-16x16.png" sizes="16x16">
<!-- favicon-32x32.png - For Safari on Mac OS. -->
<link rel="icon" type="image/png" href="/content/images/favicon-32x32.png" sizes="32x32">

<!-- Android/Chrome -->
<!-- manifest-json - The location of the browser configuration file. It contains locations of icon files, name of the application and default device screen orientation. Note that the name field is mandatory.
    https://developer.chrome.com/multidevice/android/installtohomescreen. -->
<link rel="manifest" href="/content/icons/manifest.json">
<!-- theme-color - The colour of the toolbar in Chrome M39+
    http://updates.html5rocks.com/2014/11/Support-for-theme-color-in-Chrome-39-for-Android -->
<meta name="theme-color" content="#1E1E1E">
<!-- favicon-192x192.png - For Android Chrome M36 to M38 this HTML is used. M39+ uses the manifest.json file. -->
<link rel="icon" type="image/png" href="/content/icons/favicon-192x192.png" sizes="192x192">
<!-- mobile-web-app-capable - Run Android/Chrome version M31 to M38 in standalone mode, hiding the browser chrome. -->
<!-- <meta name="mobile-web-app-capable" content="yes"> -->

<!-- Apple Icons - You can move all these icons to the root of the site and remove these link elements, if you don't mind the clutter.
    https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Introduction.html#//apple_ref/doc/uid/30001261-SW1 -->
<!-- apple-mobile-web-app-title - The name of the application if pinned to the IOS start screen. -->
<!--<meta name="apple-mobile-web-app-title" content="">-->
<!-- apple-mobile-web-app-capable - Hide the browsers user interface on IOS, when the app is run in 'standalone' mode. Any links to other pages that are clicked whilst your app is in standalone mode will launch the full Safari browser. -->
<!--<meta name="apple-mobile-web-app-capable" content="yes">-->
<!-- apple-mobile-web-app-status-bar-style - default/black/black-translucent Styles the IOS status bar. Using black-translucent makes it transparent and overlays it on top of your site, so make sure you have enough margin. -->
<!--<meta name="apple-mobile-web-app-status-bar-style" content="black">-->
<!-- apple-touch-icon-57x57.png - Android Stock Browser and non-Retina iPhone and iPod Touch -->
<link rel="apple-touch-icon" sizes="57x57" href="/content/images/apple-touch-icon-57x57.png">
<!-- apple-touch-icon-114x114.png - iPhone (with 2× display) iOS = 6 -->
<link rel="apple-touch-icon" sizes="114x114" href="/content/images/apple-touch-icon-114x114.png">
<!-- apple-touch-icon-72x72.png - iPad mini and the first- and second-generation iPad (1× display) on iOS = 6 -->
<link rel="apple-touch-icon" sizes="72x72" href="/content/images/apple-touch-icon-72x72.png">
<!-- apple-touch-icon-144x144.png - iPad (with 2× display) iOS = 6 -->
<link rel="apple-touch-icon" sizes="144x144" href="/content/images/apple-touch-icon-144x144.png">
<!-- apple-touch-icon-60x60.png - Same as apple-touch-icon-57x57.png, for non-retina iPhone with iOS7. -->
<link rel="apple-touch-icon" sizes="60x60" href="/content/images/apple-touch-icon-60x60.png">
<!-- apple-touch-icon-120x120.png - iPhone (with 2× and 3 display) iOS = 7 -->
<link rel="apple-touch-icon" sizes="120x120" href="/content/images/apple-touch-icon-120x120.png">
<!-- apple-touch-icon-76x76.png - iPad mini and the first- and second-generation iPad (1× display) on iOS = 7 -->
<link rel="apple-touch-icon" sizes="76x76" href="/content/images/apple-touch-icon-76x76.png">
<!-- apple-touch-icon-152x152.png - iPad 3+ (with 2× display) iOS = 7 -->
<link rel="apple-touch-icon" sizes="152x152" href="/content/images/apple-touch-icon-152x152.png">
<!-- apple-touch-icon-180x180.png - iPad and iPad mini (with 2× display) iOS = 8 -->
<link rel="apple-touch-icon" sizes="180x180" href="/content/images/apple-touch-icon-180x180.png">

<!-- Apple Startup Images - These are shown when the page is loading if the site is pinned https://gist.github.com/tfausak/2222823 -->
<!-- apple-touch-startup-image-1536x2008.png - iOS 6 & 7 iPad (retina, portrait) -->
<link rel="apple-touch-startup-image"
      href="/content/images/apple-touch-startup-image-1536x2008.png"
      media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)">
<!-- apple-touch-startup-image-1496x2048.png - iOS 6 & 7 iPad (retina, landscape) -->
<link rel="apple-touch-startup-image"
      href="/content/images/apple-touch-startup-image-1496x2048.png"
      media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)">
<!-- apple-touch-startup-image-768x1004.png - iOS 6 iPad (portrait) -->
<link rel="apple-touch-startup-image"
      href="/content/images/apple-touch-startup-image-768x1004.png"
      media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 1)">
<!-- apple-touch-startup-image-748x1024.png - iOS 6 iPad (landscape) -->
<link rel="apple-touch-startup-image"
      href="/content/images/apple-touch-startup-image-748x1024.png"
      media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 1)">
<!-- apple-touch-startup-image-640x1096.png - iOS 6 & 7 iPhone 5 -->
<link rel="apple-touch-startup-image"
      href="/content/images/apple-touch-startup-image-640x1096.png"
      media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)">
<!-- apple-touch-startup-image-640x920.png - iOS 6 & 7 iPhone (retina) -->
<link rel="apple-touch-startup-image"
      href="/content/images/apple-touch-startup-image-640x920.png"
      media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)">
<!-- apple-touch-startup-image-320x460.png - iOS 6 iPhone -->
<link rel="apple-touch-startup-image"
      href="/content/images/apple-touch-startup-image-320x460.png"
      media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 1)">

<!-- Windows 8 Icons - If you add an RSS feed, revisit this page and regenerate the browserconfig.xml file. You will then have a cool live tile!
     browserconfig.xml - Windows 8.1 - Has been added to the root of the site. This points to the tile images and tile background colour. It contains the following images:
     mstile-70x70.png - For Windows 8.1 / IE11.
     mstile-144x144.png - For Windows 8 / IE10.
     mstile-150x150.png - For Windows 8.1 / IE11.
     mstile-310x310.png - For Windows 8.1 / IE11.
     mstile-310x150.png - For Windows 8.1 / IE11.
     See http://www.buildmypinnedsite.com/en and http://msdn.microsoft.com/en-gb/library/ie/dn255024%28v=vs.85%29.aspx. -->
<!-- application-name - Windows 8+ - The name of the application if pinned to the start screen. -->
<!--<meta name="application-name" content="">-->
<!-- msapplication-TileColor - Windows 8 - The tile colour which shows around your tile image (msapplication-TileImage). -->
<meta name="msapplication-TileColor" content="#5cb95c">
<!-- msapplication-TileImage - Windows 8 - The tile image. -->
<meta name="msapplication-TileImage" content="/content/images/mstile-144x144.png">

我的 browserconfig.xml 文件。上面有完整的解释。

<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
  <msapplication>
    <tile>
      <square70x70logo src="/Content/Images/mstile-70x70.png"/>
      <square150x150logo src="/Content/Images/mstile-150x150.png"/>
      <square310x310logo src="/Content/Images/mstile-310x310.png"/>
      <wide310x150logo src="/Content/Images/mstile-310x150.png"/>
      <TileColor>#5cb95c</TileColor>
    </tile>
  </msapplication>
</browserconfig>

我的 manifest.json 文件。上面有完整的解释。

{
    "name": "ASP.NET MVC Boilerplate (Required! Update This)",
    "icons": [
        {
            "src": "\/Content\/icons\/android-chrome-36x36.png",
            "sizes": "36x36",
            "type": "image\/png",
            "density": "0.75"
        },
        {
            "src": "\/Content\/icons\/android-chrome-48x48.png",
            "sizes": "48x48",
            "type": "image\/png",
            "density": "1.0"
        },
        {
            "src": "\/Content\/icons\/android-chrome-72x72.png",
            "sizes": "72x72",
            "type": "image\/png",
            "density": "1.5"
        },
        {
            "src": "\/Content\/icons\/android-chrome-96x96.png",
            "sizes": "96x96",
            "type": "image\/png",
            "density": "2.0"
        },
        {
            "src": "\/Content\/icons\/android-chrome-144x144.png",
            "sizes": "144x144",
            "type": "image\/png",
            "density": "3.0"
        },
        {
            "src": "\/Content\/icons\/android-chrome-192x192.png",
            "sizes": "192x192",
            "type": "image\/png",
            "density": "4.0"
        }
    ]
}

项目中的文件列表(请注意,如果您决定将其中一些文件放在项目的根目录以避免使用上述元标记,则这些文件的名称很重要):

favicon.ico
browserconfig.xml
Content/Images/
    android-chrome-144x144.png
    android-chrome-192x192.png
    android-chrome-36x36.png
    android-chrome-48x48.png
    android-chrome-72x72.png
    android-chrome-96x96.png
    apple-touch-icon.png
    apple-touch-icon-57x57.png
    apple-touch-icon-60x60.png
    apple-touch-icon-72x72.png
    apple-touch-icon-76x76.png
    apple-touch-icon-114x114.png
    apple-touch-icon-120x120.png
    apple-touch-icon-144x144.png
    apple-touch-icon-152x152.png
    apple-touch-icon-180x180.png
    apple-touch-icon-precomposed.png (180x180)
    favicon-16x16.png
    favicon-32x32.png
    favicon-96x96.png
    favicon-192x192.png
    manifest.json
    mstile-70x70.png
    mstile-144x144.png
    mstile-150x150.png
    mstile-310x150.png
    mstile-310x310.png
    apple-touch-startup-image-1536x2008.png
    apple-touch-startup-image-1496x2048.png
    apple-touch-startup-image-768x1004.png
    apple-touch-startup-image-748x1024.png
    apple-touch-startup-image-640x1096.png
    apple-touch-startup-image-640x920.png
    apple-touch-startup-image-320x460.png

总开销

如果您取出 3KB 额外 HTML 的 cmets,如果您不支持 1.5KB 的初始屏幕。如果您在 HTML 内容上使用 GZIP 压缩(现在每个人都应该这样做),那么每个请求的开销约为 634 字节以支持所有平台或 446 字节而没有启动屏幕。我个人认为支持 IOS、Android 和 Windows 设备是值得的,但这是您的选择,我只是提供选项!

关于当前 Web 图标/启动画面/设置情况的附注

这种使用供应商特定图标、启动屏幕和特殊标签来控制网络浏览器或固定图标的情况是荒谬的。在一个完美的世界中,我们都将使用一个 favicon.svg 文件,该文件可以在任何大小下看起来都不错,并且可以放在页面的根部。在撰写本文时,只有 FireFox 支持此功能(请参阅 CanIUse.com)。

然而,如今图标并不是唯一的设置,还有其他几个特定于供应商的设置(如上所示),但 favicon.svg 文件将涵盖大多数用例。

更新

更新为包含新的 Android/Chrome 版本 M39+ 图标/主题选项。有趣的是,他们采用了与 Microsoft 类似的方法,但使用的是 JSON 文件而不是 XML。

【讨论】:

  • 这太多了。 (不是你的答案,而是浏览器供应商有这么多要求的事实:))。
  • @jor 完全同意,这是一个愚蠢的情况。 svg favicon 可以解决 90% 的问题。
  • 看我的回答stackoverflow.com/a/45301651/661584 容易多了。可能有帮助。谢谢
  • 您提到文件的名称很重要。我不太明白你指的是什么。我的问题是,我可以重命名所有文件,使其前缀为favicon-... - 如果我更新清单中的名称和html文档head中的&lt;link&gt;标签中的名称?
【解决方案4】:

最简单的解决方案是使用一个(!)PNG图像(2020年)。

只需将其添加到文档的开头即可:

<link rel="shortcut icon" type="image/png" href="/img/icon-192x192.png">
<link rel="shortcut icon" sizes="192x192" href="/img/icon-192x192.png">
<link rel="apple-touch-icon" href="/img/icon-192x192.png">

最后一个链接适用于 Apple(主屏幕),第二个链接适用于 Android(主屏幕),第一个链接适用于其余部分。

请注意,此解决方案不支持 Windows 8/10 中的“磁贴”。它确实支持快捷方式、书签和浏览器标签中的图像。

大小正是 Android 主屏幕使用的大小。 Apple 主屏幕图标大小为 60 像素(3x),因此为 180 像素,并将按比例缩小。其他平台使用默认快捷方式图标,也会按比例缩小。

【讨论】:

【解决方案5】:

我实际上也在问自己同样的问题,并试图寻找任何可以集成到构建步骤中或只是简化所需资产和标记的创建的简单项目。

我没有找到任何符合我要求的东西,所以我创建了faviconbuild 并在MIT license 下发布了它。

该项目的目的是创建一个集中的、可维护的和本地可运行的跨平台实用程序,以构建网站图标和支持标记。它利用了Imagemagick 的强大功能,因此您需要为您的平台下载它或使用我在releases 中提供的那些。请随意将其用于商业或个人项目、贡献、提交功能请求,或仅用作您自己的实用程序的灵感来源。

该项目由一个适用于 Windows 的批处理文件和一个适用于 Unix/Mac(或通过 Cygwin 的 Windows)的 bash 脚本组成。您可以从内部帮助选项 -h 或 --help 中获取受支持选项的完整列表。

例如:

./faviconbuild.sh -h

两个脚本都解析一个简单的text file,您也可以使用 -p 或 --parsed 选项覆盖它。该文件基本上只是要运行的命令模板,因此您可以在需要时更轻松地自定义输出。

我还发布了关于开发的blog post,并作为关于 bash/batch 脚本的迷你教程。

【讨论】:

    猜你喜欢
    • 2010-10-06
    • 2011-10-28
    • 2010-09-10
    • 2011-10-11
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多